summaryrefslogtreecommitdiff
path: root/python-swiglpk.spec
blob: 2442a823c077b0c2e923395bf05480b474775912 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
%global _empty_manifest_terminate_build 0
Name:		python-swiglpk
Version:	5.0.8
Release:	1
Summary:	swiglpk - Simple swig bindings for the GNU Linear Programming Kit
License:	GPL v3
URL:		https://github.com/biosustain/swiglpk
Source0:	https://mirrors.nju.edu.cn/pypi/web/packages/1e/c5/19eb970b1ccbc048e76960cb608726b52dd4826eabebb335333a458154c9/swiglpk-5.0.8.tar.gz


%description
*Plain python bindings for the GNU Linear Programming Kit (GLPK)*
|PyPI| |License| |Build Status|
Why?
~~~~
*swiglpk* is not a high-level wrapper for GLPK (take a look at
`optlang <https://github.com/biosustain/optlang>`__ if you are
interested in a python-based mathematical programming language). It just
provides plain vanilla `swig <http://www.swig.org/>`__ bindings to the
underlying C library. In constrast to other GLPK wrappers for python
(e.g. `PyGLPK <http://tfinley.net/software/pyglpk/>`__,
`Python-GLPK <http://www.dcc.fc.up.pt/~jpp/code/python-glpk/>`__,
`ctypes-glpk <https://code.google.com/p/ctypes-glpk/>`__,
`ecyglpki <https://github.com/equaeghe/ecyglpki>`__ etc.) it is fairly
version agnostic: it will try to guess the location of the glpk.h header
file (using ``which glpsol``) and then compile the extension for your
particular GLPK installation. Furthermore, swiglpk provides binary wheels
for all major platforms, which are always up-to-date with the most
recent GLPK version (swiglpk versions follow GLPK versioning in the major
and minor version digits to emphasize that).
Please show us some love by staring this repo if you find swiglpk useful!
Installation
~~~~~~~~~~~~
    pip install swiglpk
That's it. swiglpk comes with binary wheels for Windows, Mac, and Linux. No installation of third-party dependencies necessary.
Example
~~~~~~~
Running the following (slightly adapted) example from the `GLPK
manual <http://kam.mff.cuni.cz/~elias/glpk.pdf>`__ ...
    from swiglpk import *
    ia = intArray(1+1000); ja = intArray(1+1000);
    ar = doubleArray(1+1000);
    lp = glp_create_prob();
    glp_set_prob_name(lp, "sample");
    glp_set_obj_dir(lp, GLP_MAX);
    glp_add_rows(lp, 3);
    glp_set_row_name(lp, 1, "p");
    glp_set_row_bnds(lp, 1, GLP_UP, 0.0, 100.0);
    glp_set_row_name(lp, 2, "q");
    glp_set_row_bnds(lp, 2, GLP_UP, 0.0, 600.0);
    glp_set_row_name(lp, 3, "r");
    glp_set_row_bnds(lp, 3, GLP_UP, 0.0, 300.0);
    glp_add_cols(lp, 3);
    glp_set_col_name(lp, 1, "x1");
    glp_set_col_bnds(lp, 1, GLP_LO, 0.0, 0.0);
    glp_set_obj_coef(lp, 1, 10.0);
    glp_set_col_name(lp, 2, "x2");
    glp_set_col_bnds(lp, 2, GLP_LO, 0.0, 0.0);
    glp_set_obj_coef(lp, 2, 6.0);
    glp_set_col_name(lp, 3, "x3");
    glp_set_col_bnds(lp, 3, GLP_LO, 0.0, 0.0);
    glp_set_obj_coef(lp, 3, 4.0);
    ia[1] = 1; ja[1] = 1; ar[1] = 1.0; # a[1,1] = 1
    ia[2] = 1; ja[2] = 2; ar[2] = 1.0; # a[1,2] = 1
    ia[3] = 1; ja[3] = 3; ar[3] = 1.0; # a[1,3] = 1
    ia[4] = 2; ja[4] = 1; ar[4] = 10.0; # a[2,1] = 10
    ia[5] = 3; ja[5] = 1; ar[5] = 2.0; # a[3,1] = 2
    ia[6] = 2; ja[6] = 2; ar[6] = 4.0; # a[2,2] = 4
    ia[7] = 3; ja[7] = 2; ar[7] = 2.0; # a[3,2] = 2
    ia[8] = 2; ja[8] = 3; ar[8] = 5.0; # a[2,3] = 5
    ia[9] = 3; ja[9] = 3; ar[9] = 6.0; # a[3,3] = 6
    glp_load_matrix(lp, 9, ia, ja, ar);
    glp_simplex(lp, None);
    Z = glp_get_obj_val(lp);
    x1 = glp_get_col_prim(lp, 1);
    x2 = glp_get_col_prim(lp, 2);
    x3 = glp_get_col_prim(lp, 3);
    print("\nZ = %g; x1 = %g; x2 = %g; x3 = %g\n" % (Z, x1, x2, x3))
    glp_delete_prob(lp);
examples/example.py):
    GLPK Simplex Optimizer, v4.52
    3 rows, 3 columns, 9 non-zeros
    *     0: obj =   0.000000000e+00  infeas =  0.000e+00 (0)
    *     2: obj =   7.333333333e+02  infeas =  0.000e+00 (0)
    OPTIMAL LP SOLUTION FOUND
    Z = 733.333; x1 = 33.3333; x2 = 66.6667; x3 = 0
Pretty ugly right? Consider using `optlang <https://github.com/biosustain/optlang>`__ for formulating and solving your optimization problems.
Documentation
~~~~~~~~~~~~~
You can find documentation on GLPK's C API `here <http://kam.mff.cuni.cz/~elias/glpk.pdf>`__
Development
~~~~~~~~~~~
You still want to install it from source? Then you'll need to install the following
dependencies first.
-  GLPK
-  swig
If you're on OS X, swig and GLPK can easily be installed with
`homebrew <http://brew.sh/>`__.
    brew install swig glpk
If you're using ubuntu linux, you can install swig and GLPK using
``apt-get``.
    apt-get install glpk-utils libglpk-dev swig
If you're on Windows, you are on your own (checkout the `appveyor.yml <https://github.com/biosustain/swiglpk/blob/master/appveyor.yml>`_ config file for directions).
Then clone the repo and run the following.
    python setup.py install

%package -n python3-swiglpk
Summary:	swiglpk - Simple swig bindings for the GNU Linear Programming Kit
Provides:	python-swiglpk
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
BuildRequires:	python3-cffi
BuildRequires:	gcc
BuildRequires:	gdb
%description -n python3-swiglpk
*Plain python bindings for the GNU Linear Programming Kit (GLPK)*
|PyPI| |License| |Build Status|
Why?
~~~~
*swiglpk* is not a high-level wrapper for GLPK (take a look at
`optlang <https://github.com/biosustain/optlang>`__ if you are
interested in a python-based mathematical programming language). It just
provides plain vanilla `swig <http://www.swig.org/>`__ bindings to the
underlying C library. In constrast to other GLPK wrappers for python
(e.g. `PyGLPK <http://tfinley.net/software/pyglpk/>`__,
`Python-GLPK <http://www.dcc.fc.up.pt/~jpp/code/python-glpk/>`__,
`ctypes-glpk <https://code.google.com/p/ctypes-glpk/>`__,
`ecyglpki <https://github.com/equaeghe/ecyglpki>`__ etc.) it is fairly
version agnostic: it will try to guess the location of the glpk.h header
file (using ``which glpsol``) and then compile the extension for your
particular GLPK installation. Furthermore, swiglpk provides binary wheels
for all major platforms, which are always up-to-date with the most
recent GLPK version (swiglpk versions follow GLPK versioning in the major
and minor version digits to emphasize that).
Please show us some love by staring this repo if you find swiglpk useful!
Installation
~~~~~~~~~~~~
    pip install swiglpk
That's it. swiglpk comes with binary wheels for Windows, Mac, and Linux. No installation of third-party dependencies necessary.
Example
~~~~~~~
Running the following (slightly adapted) example from the `GLPK
manual <http://kam.mff.cuni.cz/~elias/glpk.pdf>`__ ...
    from swiglpk import *
    ia = intArray(1+1000); ja = intArray(1+1000);
    ar = doubleArray(1+1000);
    lp = glp_create_prob();
    glp_set_prob_name(lp, "sample");
    glp_set_obj_dir(lp, GLP_MAX);
    glp_add_rows(lp, 3);
    glp_set_row_name(lp, 1, "p");
    glp_set_row_bnds(lp, 1, GLP_UP, 0.0, 100.0);
    glp_set_row_name(lp, 2, "q");
    glp_set_row_bnds(lp, 2, GLP_UP, 0.0, 600.0);
    glp_set_row_name(lp, 3, "r");
    glp_set_row_bnds(lp, 3, GLP_UP, 0.0, 300.0);
    glp_add_cols(lp, 3);
    glp_set_col_name(lp, 1, "x1");
    glp_set_col_bnds(lp, 1, GLP_LO, 0.0, 0.0);
    glp_set_obj_coef(lp, 1, 10.0);
    glp_set_col_name(lp, 2, "x2");
    glp_set_col_bnds(lp, 2, GLP_LO, 0.0, 0.0);
    glp_set_obj_coef(lp, 2, 6.0);
    glp_set_col_name(lp, 3, "x3");
    glp_set_col_bnds(lp, 3, GLP_LO, 0.0, 0.0);
    glp_set_obj_coef(lp, 3, 4.0);
    ia[1] = 1; ja[1] = 1; ar[1] = 1.0; # a[1,1] = 1
    ia[2] = 1; ja[2] = 2; ar[2] = 1.0; # a[1,2] = 1
    ia[3] = 1; ja[3] = 3; ar[3] = 1.0; # a[1,3] = 1
    ia[4] = 2; ja[4] = 1; ar[4] = 10.0; # a[2,1] = 10
    ia[5] = 3; ja[5] = 1; ar[5] = 2.0; # a[3,1] = 2
    ia[6] = 2; ja[6] = 2; ar[6] = 4.0; # a[2,2] = 4
    ia[7] = 3; ja[7] = 2; ar[7] = 2.0; # a[3,2] = 2
    ia[8] = 2; ja[8] = 3; ar[8] = 5.0; # a[2,3] = 5
    ia[9] = 3; ja[9] = 3; ar[9] = 6.0; # a[3,3] = 6
    glp_load_matrix(lp, 9, ia, ja, ar);
    glp_simplex(lp, None);
    Z = glp_get_obj_val(lp);
    x1 = glp_get_col_prim(lp, 1);
    x2 = glp_get_col_prim(lp, 2);
    x3 = glp_get_col_prim(lp, 3);
    print("\nZ = %g; x1 = %g; x2 = %g; x3 = %g\n" % (Z, x1, x2, x3))
    glp_delete_prob(lp);
examples/example.py):
    GLPK Simplex Optimizer, v4.52
    3 rows, 3 columns, 9 non-zeros
    *     0: obj =   0.000000000e+00  infeas =  0.000e+00 (0)
    *     2: obj =   7.333333333e+02  infeas =  0.000e+00 (0)
    OPTIMAL LP SOLUTION FOUND
    Z = 733.333; x1 = 33.3333; x2 = 66.6667; x3 = 0
Pretty ugly right? Consider using `optlang <https://github.com/biosustain/optlang>`__ for formulating and solving your optimization problems.
Documentation
~~~~~~~~~~~~~
You can find documentation on GLPK's C API `here <http://kam.mff.cuni.cz/~elias/glpk.pdf>`__
Development
~~~~~~~~~~~
You still want to install it from source? Then you'll need to install the following
dependencies first.
-  GLPK
-  swig
If you're on OS X, swig and GLPK can easily be installed with
`homebrew <http://brew.sh/>`__.
    brew install swig glpk
If you're using ubuntu linux, you can install swig and GLPK using
``apt-get``.
    apt-get install glpk-utils libglpk-dev swig
If you're on Windows, you are on your own (checkout the `appveyor.yml <https://github.com/biosustain/swiglpk/blob/master/appveyor.yml>`_ config file for directions).
Then clone the repo and run the following.
    python setup.py install

%package help
Summary:	Development documents and examples for swiglpk
Provides:	python3-swiglpk-doc
%description help
*Plain python bindings for the GNU Linear Programming Kit (GLPK)*
|PyPI| |License| |Build Status|
Why?
~~~~
*swiglpk* is not a high-level wrapper for GLPK (take a look at
`optlang <https://github.com/biosustain/optlang>`__ if you are
interested in a python-based mathematical programming language). It just
provides plain vanilla `swig <http://www.swig.org/>`__ bindings to the
underlying C library. In constrast to other GLPK wrappers for python
(e.g. `PyGLPK <http://tfinley.net/software/pyglpk/>`__,
`Python-GLPK <http://www.dcc.fc.up.pt/~jpp/code/python-glpk/>`__,
`ctypes-glpk <https://code.google.com/p/ctypes-glpk/>`__,
`ecyglpki <https://github.com/equaeghe/ecyglpki>`__ etc.) it is fairly
version agnostic: it will try to guess the location of the glpk.h header
file (using ``which glpsol``) and then compile the extension for your
particular GLPK installation. Furthermore, swiglpk provides binary wheels
for all major platforms, which are always up-to-date with the most
recent GLPK version (swiglpk versions follow GLPK versioning in the major
and minor version digits to emphasize that).
Please show us some love by staring this repo if you find swiglpk useful!
Installation
~~~~~~~~~~~~
    pip install swiglpk
That's it. swiglpk comes with binary wheels for Windows, Mac, and Linux. No installation of third-party dependencies necessary.
Example
~~~~~~~
Running the following (slightly adapted) example from the `GLPK
manual <http://kam.mff.cuni.cz/~elias/glpk.pdf>`__ ...
    from swiglpk import *
    ia = intArray(1+1000); ja = intArray(1+1000);
    ar = doubleArray(1+1000);
    lp = glp_create_prob();
    glp_set_prob_name(lp, "sample");
    glp_set_obj_dir(lp, GLP_MAX);
    glp_add_rows(lp, 3);
    glp_set_row_name(lp, 1, "p");
    glp_set_row_bnds(lp, 1, GLP_UP, 0.0, 100.0);
    glp_set_row_name(lp, 2, "q");
    glp_set_row_bnds(lp, 2, GLP_UP, 0.0, 600.0);
    glp_set_row_name(lp, 3, "r");
    glp_set_row_bnds(lp, 3, GLP_UP, 0.0, 300.0);
    glp_add_cols(lp, 3);
    glp_set_col_name(lp, 1, "x1");
    glp_set_col_bnds(lp, 1, GLP_LO, 0.0, 0.0);
    glp_set_obj_coef(lp, 1, 10.0);
    glp_set_col_name(lp, 2, "x2");
    glp_set_col_bnds(lp, 2, GLP_LO, 0.0, 0.0);
    glp_set_obj_coef(lp, 2, 6.0);
    glp_set_col_name(lp, 3, "x3");
    glp_set_col_bnds(lp, 3, GLP_LO, 0.0, 0.0);
    glp_set_obj_coef(lp, 3, 4.0);
    ia[1] = 1; ja[1] = 1; ar[1] = 1.0; # a[1,1] = 1
    ia[2] = 1; ja[2] = 2; ar[2] = 1.0; # a[1,2] = 1
    ia[3] = 1; ja[3] = 3; ar[3] = 1.0; # a[1,3] = 1
    ia[4] = 2; ja[4] = 1; ar[4] = 10.0; # a[2,1] = 10
    ia[5] = 3; ja[5] = 1; ar[5] = 2.0; # a[3,1] = 2
    ia[6] = 2; ja[6] = 2; ar[6] = 4.0; # a[2,2] = 4
    ia[7] = 3; ja[7] = 2; ar[7] = 2.0; # a[3,2] = 2
    ia[8] = 2; ja[8] = 3; ar[8] = 5.0; # a[2,3] = 5
    ia[9] = 3; ja[9] = 3; ar[9] = 6.0; # a[3,3] = 6
    glp_load_matrix(lp, 9, ia, ja, ar);
    glp_simplex(lp, None);
    Z = glp_get_obj_val(lp);
    x1 = glp_get_col_prim(lp, 1);
    x2 = glp_get_col_prim(lp, 2);
    x3 = glp_get_col_prim(lp, 3);
    print("\nZ = %g; x1 = %g; x2 = %g; x3 = %g\n" % (Z, x1, x2, x3))
    glp_delete_prob(lp);
examples/example.py):
    GLPK Simplex Optimizer, v4.52
    3 rows, 3 columns, 9 non-zeros
    *     0: obj =   0.000000000e+00  infeas =  0.000e+00 (0)
    *     2: obj =   7.333333333e+02  infeas =  0.000e+00 (0)
    OPTIMAL LP SOLUTION FOUND
    Z = 733.333; x1 = 33.3333; x2 = 66.6667; x3 = 0
Pretty ugly right? Consider using `optlang <https://github.com/biosustain/optlang>`__ for formulating and solving your optimization problems.
Documentation
~~~~~~~~~~~~~
You can find documentation on GLPK's C API `here <http://kam.mff.cuni.cz/~elias/glpk.pdf>`__
Development
~~~~~~~~~~~
You still want to install it from source? Then you'll need to install the following
dependencies first.
-  GLPK
-  swig
If you're on OS X, swig and GLPK can easily be installed with
`homebrew <http://brew.sh/>`__.
    brew install swig glpk
If you're using ubuntu linux, you can install swig and GLPK using
``apt-get``.
    apt-get install glpk-utils libglpk-dev swig
If you're on Windows, you are on your own (checkout the `appveyor.yml <https://github.com/biosustain/swiglpk/blob/master/appveyor.yml>`_ config file for directions).
Then clone the repo and run the following.
    python setup.py install

%prep
%autosetup -n swiglpk-5.0.8

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-swiglpk -f filelist.lst
%dir %{python3_sitearch}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Tue Apr 25 2023 Python_Bot <Python_Bot@openeuler.org> - 5.0.8-1
- Package Spec generated