help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-glpk] Re: python-glpk


From: Nigel Galloway
Subject: [Help-glpk] Re: python-glpk
Date: Mon, 16 Feb 2009 18:40:52 +0300

Attached is sample.py which impliments the example from glpk.pdf in Python 
using Swig's array functions, running it produces:

address@hidden:~/myGLPK$ python sample.py
*     0: obj =   0.000000000e+00  infeas =  0.000e+00 (0)
*     2: obj =   7.333333333e+02  infeas =  0.000e+00 (0)
OPTIMAL SOLUTION FOUND

Z =  733.333333333 ; x1 =  33.3333333333 ; x2 =  66.6666666667 ; x3 =  0.0

The original can be found in:

http://geocities.yahoo.com/nigel_galloway/SWIG_GLPK.pdf dated June 1st., 2007

In summary:

Python 2.5.2 (r252:60911, Mar  1 2008, 13:52:45)
[GCC 4.2.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import nigelzGLPK

using Swig's array functions:

>>> ia = nigelzGLPK.new_intArray(5)
>>> ja = nigelzGLPK.new_intArray(5)
>>> ar = nigelzGLPK.new_doubleArray(5)
>>> nigelzGLPK.intArray_setitem(ia,1,1)
>>> nigelzGLPK.intArray_setitem(ja,1,1)
>>> nigelzGLPK.doubleArray_setitem(ar,1,5.0)
>>>

using IAJAAR:

>>> p = nigelzGLPK.iajaar(5)
>>> p.Add(1,1,5.0)
>>>
>>>

now lets break it

>>>
>>> p.Add(2,2,23.0)
>>> p.Add(3,5,-4.8)
>>> p.Add(4,1,0)
>>> p.Add(5,3,-10)
>>> p.Add(6,1,13)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "nigelzGLPK.py", line 76, in Add
    def Add(*args): return _nigelzGLPK.iajaar_Add(*args)
nigelzGLPK.iajaarFull: <nigelzGLPK.iajaarFull; proxy of <Swig Object of type 
'iajaarFull *' at 0x80f2cd0> >
>>>

which compares well to breaking Swig's array functions (or classes). 


--- On Tue, 10/2/09, Joao Pedro Pedroso <address@hidden> wrote:

> From: Joao Pedro Pedroso <address@hidden>
> Subject: python-glpk + Re: [Help-glpk] SWIG for Visual Studio 2008, C#, and 
> GLPK
> To: address@hidden
> Cc: address@hidden
> Date: Tuesday, 10 February, 2009, 7:05 AM
> Nigel,
> 
> > Firstly, intArray and doubleArray are just my names.
> If you want to
> > include both it is only necassary to use different
> names for the
> > class arrays.
> 
> I was tempted to say that they are just MY names, because I
> said first
> ;-) but then I realized that I just copied/pasted them from
> the swig
> documentation.  So the copyright is not mine.  :-(
> 
> > Secondly array functions work with Python.
> 
> I could not figure out how... (*)
> 
> > Finally, to celebrate the long struggle to get these
> multiple defines removed and the start of the struggle to
> get 'in' and 'out' removed see:
> >  
> http://lists.gnu.org/archive/html/help-glpk/2007-06/msg00000.html
> 
> I am afraid I could not understand what you suggest.
> 
> Anyway, I guess that your reluctance on accepting the lines
> %array_class(int, intArray);
> %array_class(double, doubleArray);
> comes from some incompatibility issues in Java, and decided
> to keep
> python-glpk with a different swig interface for the time
> being.
> 
> The current version is 0.1.36, available at the usual
> place:
>   http://www.dcc.fc.up.pt/~jpp/code/python-glpk/
> 
> Enjoy,
> 
> Pedro
> --
> (*) I hope you did not mean use it as follows; did you?
> a = new_doubleArray(10)           # Create an array
> for i in range(0,10):
>     doubleArray_setitem(a,i,2*i)  # Set a value
> print_array(a)                    # Pass to C
> delete_doubleArray(a)             # Destroy array
> 
> Current usage of C arrays in python-glpk is something like:
> >>> a = intArray(10000000)         # Array of
> 10-million integers
> >>> for i in xrange(10000):        # Set some
> values
> ...     a[i] = i
> >>> sumitems(a,10000)              # call C
> function 
> 49995000
> >>>
> 
> > > ----- Original Message -----
> > > From: xypron <address@hidden>
> > > To: address@hidden
> > > Subject: Re: [Help-glpk] SWIG for Visual Studio
> 2008, C#, and GLPK
> > > Date: Thu, 5 Feb 2009 12:43:11 -0800 (PST)
> > >
> > >
> > >
> > > Hello Nigel,
> > >
> > > thank you for your contribution. It would make
> sense to integrate
> > > instructions for creating c# libraries for GLPK
> with swig into the GLPK
> > > distribution.
> > >
> > > Glpk is based on the GNU licence. Hence binaries
> can only be published if
> > > the source is made available.
> > >
> > > For using glpk with C# you describe.
> > > >> 5. Open Project -> Add Reference
> -> Browse, then select:
> > > >>     glpkSWIG.dll
> > > >>     and nigelzGLPK.dll.
> > >
> > > How can the dlls be created from source?
> > >
> > > Best regards
> > >
> > > Xypron


Attachment: sample.py
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]