Skip to content

Commit 80b16ef

Browse files
committed
Merge branch 'latest' of https://github.com/ERGO-Code/HiGHS into latest
2 parents 49e2988 + cb58465 commit 80b16ef

File tree

17 files changed

+192
-85
lines changed

17 files changed

+192
-85
lines changed

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Documenter.makedocs(
8888
"Python" => Any[
8989
"interfaces/python/index.md",
9090
"interfaces/python/example-py.md",
91+
"interfaces/python/model-py.md",
9192
],
9293
"CSharp" => "interfaces/csharp.md",
9394
"Julia" => "interfaces/julia/index.md",

docs/src/interfaces/python/index.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ To use `highspy` within a Python program, it must be imported
1818
import highspy
1919
```
2020

21-
When using `highspy`, it is likely that `numpy` structures will be needed,
22-
so must also be imported
23-
24-
```python
25-
import numpy as np
26-
```
27-
2821
## Initialize
2922

3023
HiGHS must be initialized before making calls to the HiGHS Python library:
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# [Modelling](@id model-py)
2+
3+
HiGHS has a rudimentry modelling language that allows models to be built and run using `highspy`.
4+
5+
Below is an example of building a mathematical LP. The functions used are documented in detail below
6+
```
7+
# model and solve the LP
8+
#
9+
# maximize 10 x1 + 25x2
10+
# s. t. x1 + 2x2 <= 80
11+
# x1 + 4x2 <= 120
12+
# x1 >= 0; x2 >= 0
13+
import highspy
14+
15+
h = highspy.Highs()
16+
17+
x1 = h.addVar()
18+
x2 = h.addVar()
19+
20+
h.addConstr(x1 + 2*x2 <= 80)
21+
h.addConstr(x1 + 4*x2 <= 120)
22+
23+
h.maximize(10*x1 + 25*x2)
24+
25+
print("x1 = ", h.val(x1))
26+
print("x2 = ", h.val(x2))
27+
```
28+
29+
## addVar
30+
31+
Adds a variable to the model. By default it is continuous,
32+
non-negative, with zero objective coefficient, and has no name
33+
associated with it.
34+
35+
```
36+
addVar(lb = 0, ub = kHighsInf, obj = 0, type=HighsVarType.kContinuous, name = None)
37+
```
38+
39+
## addConstr
40+
41+
Adds a constraint to the model. It must be defined in terms of a
42+
linear function, with `*` used when there are non-unit
43+
coefficients. By default it has a lower bound of -infinity, an upper
44+
bound of +infinity, and no name associated with it.
45+
46+
```
47+
addConstr(cons, name = None)
48+
```
49+
50+
## maximize
51+
52+
Calls HiGHS to maximize the objective. By default it uses the
53+
objective coefficients defined when the variables were added to the
54+
model. However, a linear function can be passed as an argument.
55+
56+
```
57+
maximize(obj=None)
58+
```
59+
60+
## minimize
61+
62+
Calls HiGHS to minimize the objective. By default it uses the
63+
objective coefficients defined when the variables were added to the
64+
model. However, a linear function can be passed as an argument.
65+
66+
```
67+
minimize(obj=None)
68+
```
69+
70+
## val
71+
72+
Extracts the current value of a particular variable
73+
74+
```
75+
val(var)
76+
```
77+
78+
## vals
79+
80+
Extracts the current values of a particular set of variables
81+
82+
```
83+
vals(vars)
84+
```
85+
86+
## MIP Example
87+
88+
89+
90+

examples/chip0.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# model and solve the LP
2+
#
3+
# maximize 10 x1 + 25x2
4+
# s. t. x1 + 2x2 <= 80
5+
# x1 + 4x2 <= 120
6+
# x1 >= 0; x2 >= 0
7+
import highspy
8+
9+
h = highspy.Highs()
10+
11+
x1 = h.addVar(obj = 10)
12+
x2 = h.addVar(obj = 25)
13+
14+
h.addConstr(x1 + 2*x2 <= 80)
15+
h.addConstr(x1 + 4*x2 <= 120)
16+
17+
h.writeModel("")
18+
print("x1 = ", h.val(x1))
19+
print("x2 = ", h.val(x2))
20+
21+
h.maximize()
22+
23+
print("x1 = ", h.val(x1))
24+
print("x2 = ", h.val(x2))
25+
26+
print("x = ", h.vals([x1, x2]))
27+
28+
29+

extern/amd/SuiteSparse_config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include "SuiteSparse_config.h"
1515

16-
void *SuiteSparse_malloc /* pointer to allocated block of memory */
16+
void *Highs_SuiteSparse_malloc /* pointer to allocated block of memory */
1717
(
1818
size_t nitems, /* number of items to malloc */
1919
size_t size_of_item /* sizeof each item */
@@ -41,7 +41,7 @@ void *SuiteSparse_malloc /* pointer to allocated block of memory */
4141
/* SuiteSparse_free: free wrapper */
4242
/* -------------------------------------------------------------------------- */
4343

44-
void *SuiteSparse_free /* always returns NULL */
44+
void *Highs_SuiteSparse_free /* always returns NULL */
4545
(
4646
void *p /* block to free */
4747
)

extern/amd/SuiteSparse_config.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,17 @@
3636
#include <stdarg.h>
3737
#include <ctype.h>
3838

39-
void *SuiteSparse_malloc // pointer to allocated block of memory
39+
void *Highs_SuiteSparse_malloc // pointer to allocated block of memory
4040
(
4141
size_t nitems, // number of items to malloc (>=1 is enforced)
4242
size_t size_of_item // sizeof each item
4343
) ;
4444

45-
void *SuiteSparse_free // always returns NULL
45+
void *Highs_SuiteSparse_free // always returns NULL
4646
(
4747
void *p // block to free
4848
) ;
4949

50-
// SuiteSparse printf macro
51-
#define SUITESPARSE_PRINTF(params) \
52-
{ \
53-
\
54-
printf params ; \
55-
\
56-
}
57-
5850
#define SUITESPARSE_DATE "Nov 4, 2025"
5951
#define SUITESPARSE_MAIN_VERSION 7
6052
#define SUITESPARSE_SUB_VERSION 12

extern/amd/amd.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ typedef unsigned int amd_uint;
5353
extern "C" {
5454
#endif
5555

56-
int amd_order /* returns AMD_OK, AMD_OK_BUT_JUMBLED,
56+
int Highs_amd_order /* returns AMD_OK, AMD_OK_BUT_JUMBLED,
5757
* AMD_INVALID, or AMD_OUT_OF_MEMORY */
5858
(
5959
amd_int n, /* A is n-by-n. n must be >= 0. */
@@ -232,7 +232,7 @@ int amd_order /* returns AMD_OK, AMD_OK_BUT_JUMBLED,
232232
* of the matrix for AMD to destroy). Refer to AMD/Source/amd_2.c for a
233233
* description of each parameter. */
234234

235-
void amd_2
235+
void Highs_amd_2
236236
(
237237
amd_int n,
238238
amd_int Pe [ ],
@@ -263,7 +263,7 @@ void amd_2
263263
* of columns of the matrix. For its use in AMD, these must both equal n.
264264
*/
265265

266-
int amd_valid
266+
int Highs_amd_valid
267267
(
268268
amd_int n_row, /* # of rows */
269269
amd_int n_col, /* # of columns */
@@ -276,13 +276,13 @@ int amd_valid
276276
/* ------------------------------------------------------------------------- */
277277

278278
/* amd_defaults: sets the default control settings */
279-
void amd_defaults (double Control [ ]) ;
279+
void Highs_amd_defaults (double Control [ ]) ;
280280

281281
/* amd_control: prints the control settings */
282-
void amd_control (double Control [ ]) ;
282+
void Highs_amd_control (double Control [ ]) ;
283283

284284
/* amd_info: prints the statistics */
285-
void amd_info (double Info [ ]) ;
285+
void Highs_amd_info (double Info [ ]) ;
286286

287287
#ifdef __cplusplus
288288
}

extern/amd/amd_1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,6 @@ void amd_1
167167
/* order the matrix */
168168
/* --------------------------------------------------------------------- */
169169

170-
amd_2 (n, Pe, Iw, Len, iwlen, pfree,
170+
Highs_amd_2 (n, Pe, Iw, Len, iwlen, pfree,
171171
Nv, Pinv, P, Head, Elen, Degree, W, Control, Info) ;
172172
}

extern/amd/amd_2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static amd_int clear_flag (amd_int wflg, amd_int wbig, amd_int W [ ], amd_int n)
3939
/* === AMD_2 =============================================================== */
4040
/* ========================================================================= */
4141

42-
void amd_2
42+
void Highs_amd_2
4343
(
4444
amd_int n, /* A is n-by-n, where n > 0 */
4545
amd_int Pe [ ], /* Pe [0..n-1]: index in Iw of row i on input */

extern/amd/amd_control.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include "amd_internal.h"
1717

18-
void amd_control
18+
void Highs_amd_control
1919
(
2020
double Control [ ]
2121
)
@@ -34,31 +34,31 @@ void amd_control
3434
aggressive = AMD_DEFAULT_AGGRESSIVE ;
3535
}
3636

37-
SUITESPARSE_PRINTF ((
37+
printf (
3838
"\nAMD version %d.%d.%d, %s: approximate minimum degree ordering\n"
3939
" dense row parameter: %g\n", AMD_MAIN_VERSION, AMD_SUB_VERSION,
40-
AMD_SUBSUB_VERSION, AMD_DATE, alpha)) ;
40+
AMD_SUBSUB_VERSION, AMD_DATE, alpha) ;
4141

4242
if (alpha < 0)
4343
{
44-
SUITESPARSE_PRINTF ((" no rows treated as dense\n")) ;
44+
printf (" no rows treated as dense\n") ;
4545
}
4646
else
4747
{
48-
SUITESPARSE_PRINTF ((
48+
printf (
4949
" (rows with more than max (%g * sqrt (n), 16) entries are\n"
5050
" considered \"dense\", and placed last in output permutation)\n",
51-
alpha)) ;
51+
alpha) ;
5252
}
5353

5454
if (aggressive)
5555
{
56-
SUITESPARSE_PRINTF ((" aggressive absorption: yes\n")) ;
56+
printf (" aggressive absorption: yes\n") ;
5757
}
5858
else
5959
{
60-
SUITESPARSE_PRINTF ((" aggressive absorption: no\n")) ;
60+
printf (" aggressive absorption: no\n") ;
6161
}
6262

63-
SUITESPARSE_PRINTF ((" size of AMD integer: %lu\n\n", sizeof (amd_int))) ;
63+
printf (" size of AMD integer: %lu\n\n", sizeof (amd_int)) ;
6464
}

0 commit comments

Comments
 (0)