1#![allow(improper_ctypes)]
2#![allow(non_camel_case_types)]
3
4pub use std::os::raw::{c_int, c_double, c_char, c_void};
5pub type c_str = *const c_char;
6
7use std::ffi::CString;
8use std::convert::From;
9
10#[repr(C)]
11pub struct GRBenv;
12
13#[repr(C)]
14pub struct GRBmodel;
15
16#[repr(C)]
17pub struct GRBsvec {
18 pub len: c_int,
20 pub ind: *mut c_int,
22 pub val: *mut c_double
24}
25
26
27#[derive(Debug,Copy,Clone)]
28pub enum IntParam {
29 SolutionLimit,
30 Method,
31 ScaleFlag,
32 SimplexPricing,
33 Quad,
34 NormAdjust,
35 Sifting,
36 SiftMethod,
37 SubMIPNodes,
38 VarBranch,
39 Cuts,
40 CliqueCuts,
41 CoverCuts,
42 FlowCoverCuts,
43 FlowPathCuts,
44 GUBCoverCuts,
45 ImpliedCuts,
46 MIPSepCuts,
47 MIRCuts,
48 ModKCuts,
49 ZeroHalfCuts,
50 NetworkCuts,
51 SubMIPCuts,
52 CutAggPasses,
53 CutPasses,
54 GomoryPasses,
55 NodeMethod,
56 Presolve,
57 Aggregate,
58 IISMethod,
59 PreCrush,
60 PreDepRow,
61 PrePasses,
62 DisplayInterval,
63 OutputFlag,
64 Threads,
65 BarIterLimit,
66 Crossover,
67 CrossoverBasis,
68 BarCorrectors,
69 BarOrder,
70 PumpPasses,
71 RINS,
72 Symmetry,
73 MIPFocus,
74 NumericFocus,
75 AggFill,
76 PreDual,
77 SolutionNumber,
78 MinRelNodes,
79 ZeroObjNodes,
80 BranchDir,
81 InfUnbdInfo,
82 DualReductions,
83 BarHomogeneous,
84 PreQLinearize,
85 MIQCPMethod,
86 QCPDual,
87 LogToConsole,
88 PreSparsify,
89 PreMIQCPForm,
90 Seed,
91 ConcurrentMIP,
92 ConcurrentJobs,
93 DistributedMIPJobs,
94 LazyConstraints,
95 TuneResults,
96 TuneTrials,
97 TuneOutput,
98 TuneJobs,
99 Disconnected,
100 NoRelHeuristic,
101 UpdateMode,
102 WorkerPort,
103 Record
104}
105
106#[derive(Debug,Copy,Clone)]
107pub enum DoubleParam {
108 Cutoff,
109 IterationLimit,
110 NodeLimit,
111 TimeLimit,
112 FeasibilityTol,
113 IntFeasTol,
114 MarkowitzTol,
115 MIPGap,
116 MIPGapAbs,
117 OptimalityTol,
118 PerturbValue,
119 Heuristics,
120 ObjScale,
121 NodefileStart,
122 BarConvTol,
123 BarQCPConvTol,
124 PSDTol,
125 ImproveStartGap,
126 ImproveStartNodes,
127 ImproveStartTime,
128 FeasRelaxBigM,
129 TuneTimeLimit,
130 PreSOS1BigM,
131 PreSOS2BigM
132}
133
134#[derive(Debug,Copy,Clone)]
135pub enum StringParam {
136 LogFile,
137 NodefileDir,
138 ResultFile,
139 WorkerPool,
140 WorkerPassword,
141 Dummy
142}
143
144#[derive(Debug,Copy,Clone)]
145pub enum IntAttr {
146 NumConstrs,
147 NumVars,
148 NumSOS,
149 NumQConstrs,
150 NumNZs,
151 NumQNZs,
152 NumQCNZs,
153 NumIntVars,
154 NumBinVars,
155 NumPWLObjVars,
156 ModelSense,
157 IsMIP,
158 IsQP,
159 IsQCP,
160 Status,
161 SolCount,
162 BarIterCount,
163 VBasis,
164 CBasis,
165 PWLObjCvx,
166 BranchPriority,
167 VarPreStat,
168 BoundVioIndex,
169 BoundSVioIndex,
170 ConstrVioIndex,
171 ConstrSVioIndex,
172 ConstrResidualIndex,
173 ConstrSResidualIndex,
174 DualVioIndex,
175 DualSVioIndex,
176 DualResidualIndex,
177 DualSResidualIndex,
178 ComplVioIndex,
179 IntVioIndex,
180 IISMinimal,
181 IISLB,
182 IISUB,
183 IISConstr,
184 IISSOS,
185 IISQConstr,
186 TuneResultCount,
187 Lazy,
188 VarHintPri
189}
190
191#[derive(Debug,Copy,Clone)]
192pub enum CharAttr {
193 VType,
194 Sense,
195 QCSense
196}
197
198#[derive(Debug,Copy,Clone)]
199pub enum DoubleAttr {
200 Runtime,
201 ObjCon,
202 LB,
203 UB,
204 Obj,
205 Start,
206 PreFixVal,
207 RHS,
208 QCRHS,
209 MaxCoeff,
210 MinCoeff,
211 MaxBound,
212 MinBound,
213 MaxObjCoeff,
214 MinObjCoeff,
215 MaxRHS,
216 MinRHS,
217 ObjVal,
218 ObjBound,
219 ObjBoundC,
220 MIPGap,
221 IterCount,
222 NodeCount,
223 X,
224 RC,
225 Pi,
226 QCPi,
227 Slack,
228 QCSlack,
229 BoundVio,
230 BoundSVio,
231 BoundVioSum,
232 BoundSVioSum,
233 ConstrVio,
234 ConstrSVio,
235 ConstrVioSum,
236 ConstrSVioSum,
237 ConstrResidual,
238 ConstrSResidual,
239 ConstrResidualSum,
240 ConstrSResidualSum,
241 DualVio,
242 DualSVio,
243 DualVioSum,
244 DualSVioSum,
245 DualResidual,
246 DualSResidual,
247 DualResidualSum,
248 DualSResidualSum,
249 ComplVio,
250 ComplVioSum,
251 IntVio,
252 IntVioSum,
253 Kappa,
254 KappaExact,
255 SAObjLow,
256 SAObjUp,
257 SALBLow,
258 SALBUp,
259 SARHSLow,
260 SAUBLow,
261 SAUBUp,
262 SARHSUp,
263 Xn,
264 FarkasProof,
265 FarkasDual,
266 UnbdRay,
267 PStart,
268 DStart,
269 BarX,
270 VarHintVal
271}
272
273#[derive(Debug,Copy,Clone)]
274pub enum StringAttr {
275 ModelName,
276 VarName,
277 ConstrName,
278 QCName
279}
280
281macro_rules! impl_from {
282 ($($t:ty)*) => ($(
283 impl From<$t> for CString {
284 fn from(attr: $t) -> CString {
285 CString::new(format!("{:?}", attr).as_str()).unwrap()
286 }
287 }
288 )*)
289}
290
291impl_from! { IntParam DoubleParam StringParam }
292impl_from! { IntAttr CharAttr DoubleAttr StringAttr }
293
294
295extern "C" {
297 pub fn GRBloadenv(envP: *mut *mut GRBenv, logfilename: c_str) -> c_int;
298
299 pub fn GRBloadclientenv(envP: *mut *mut GRBenv, logfilename: c_str, computeserver: c_str, port: c_int,
300 password: c_str, priority: c_int, timeout: c_double)
301 -> c_int;
302
303 pub fn GRBfreeenv(env: *mut GRBenv);
304
305 pub fn GRBgetconcurrentenv(model: *mut GRBmodel, num: c_int) -> *mut GRBenv;
306
307 pub fn GRBdiscardconcurrentenvs(model: *mut GRBmodel);
308}
309
310extern "C" {
312 pub fn GRBnewmodel(env: *mut GRBenv, modelP: *mut *mut GRBmodel, Pname: c_str, numvars: c_int,
313 obj: *const c_double, lb: *const c_double, ub: *const c_double, vtype: *const c_char,
314 varnames: *const c_str)
315 -> c_int;
316
317 pub fn GRBcopymodel(model: *mut GRBmodel) -> *mut GRBmodel;
318
319 pub fn GRBaddconstr(model: *mut GRBmodel, numnz: c_int, cind: *const c_int, cval: *const c_double, sense: c_char,
320 rhs: c_double, constrname: c_str)
321 -> c_int;
322
323 pub fn GRBaddconstrs(model: *mut GRBmodel, numconstrs: c_int, numnz: c_int, cbeg: *const c_int, cind: *const c_int,
324 cval: *const c_double, sense: *const c_char, rhs: *const c_double, constrname: *const c_str)
325 -> c_int;
326
327 pub fn GRBaddqconstr(model: *mut GRBmodel, numlnz: c_int, lind: *const c_int, lval: *const c_double, numqnz: c_int,
328 qrow: *const c_int, qcol: *const c_int, qval: *const c_double, sense: c_char, rhs: c_double,
329 QCname: c_str)
330 -> c_int;
331
332 pub fn GRBaddqpterms(model: *mut GRBmodel, numqnz: c_int, qrow: *const c_int, qcol: *const c_int,
333 qval: *const c_double)
334 -> c_int;
335
336 pub fn GRBaddrangeconstr(model: *mut GRBmodel, numnz: c_int, cind: *const c_int, cval: *const c_double,
337 lower: c_double, upper: c_double, constrname: c_str)
338 -> c_int;
339
340 pub fn GRBaddrangeconstrs(model: *mut GRBmodel, numconstrs: c_int, numnz: c_int, cbeg: *const c_int,
341 cind: *const c_int, cval: *const c_double, lower: *const c_double,
342 upper: *const c_double, constrname: *const c_str)
343 -> c_int;
344
345 pub fn GRBaddsos(model: *mut GRBmodel, numsos: c_int, nummembers: c_int, types: *const c_int, beg: *const c_int,
346 ind: *const c_int, weight: *const c_double)
347 -> c_int;
348
349 pub fn GRBaddvar(model: *mut GRBmodel, numnz: c_int, vind: *const c_int, vval: *const c_double, obj: f64, lb: f64,
350 ub: f64, vtype: c_char, name: c_str)
351 -> c_int;
352
353 pub fn GRBaddvars(model: *mut GRBmodel, numvars: c_int, numnz: c_int, vbeg: *const c_int, vind: *const c_int,
354 vval: *const c_double, obj: *const f64, lb: *const f64, ub: *const f64, vtype: *const c_char,
355 name: *const c_str)
356 -> c_int;
357
358 pub fn GRBchgcoeffs(model: *mut GRBmodel, cnt: c_int, cind: *const c_int, vind: *const c_int, val: *const c_double)
359 -> c_int;
360
361 pub fn GRBdelvars(model: *mut GRBmodel, numdel: c_int, ind: *const c_int) -> c_int;
362
363 pub fn GRBdelconstrs(model: *mut GRBmodel, numdel: c_int, ind: *const c_int) -> c_int;
364
365 pub fn GRBdelq(model: *mut GRBmodel) -> c_int;
366
367 pub fn GRBdelqconstrs(model: *mut GRBmodel, len: c_int, ind: *const c_int) -> c_int;
368
369 pub fn GRBdelsos(model: *mut GRBmodel, len: c_int, ind: *const c_int) -> c_int;
370
371 pub fn GRBsetpwlobj(model: *mut GRBmodel, var: c_int, points: c_int, x: *const c_double, y: *const c_double)
372 -> c_int;
373
374 pub fn GRBupdatemodel(model: *mut GRBmodel) -> c_int;
375
376 pub fn GRBfreemodel(model: *mut GRBmodel) -> c_int;
377
378}
384
385extern "C" {
387
388 pub fn GRBoptimize(model: *mut GRBmodel) -> c_int;
389
390 pub fn GRBoptimizeasync(model: *mut GRBmodel) -> c_int;
391
392 pub fn GRBcomputeIIS(model: *mut GRBmodel) -> c_int;
393
394 pub fn GRBfeasrelax(model: *mut GRBmodel, relaxobjtype: c_int, minrelax: c_int, lbpen: *const c_double,
395 ubpen: *const c_double, rhspen: *const c_double, feasobjP: *const c_double)
396 -> c_int;
397
398 pub fn GRBfixedmodel(model: *mut GRBmodel) -> *mut GRBmodel;
399
400 pub fn GRBrelaxmodel(model: *mut GRBmodel) -> *mut GRBmodel;
401
402 pub fn GRBpresolvemodel(model: *mut GRBmodel) -> *mut GRBmodel;
403
404 pub fn GRBfeasibility(model: *mut GRBmodel) -> *mut GRBmodel;
405
406 pub fn GRBresetmodel(model: *mut GRBmodel) -> c_int;
407
408 pub fn GRBsync(model: *mut GRBmodel) -> c_int;
409}
410
411extern "C" {
413 pub fn GRBgetcoeff(model: *mut GRBmodel, constr: c_int, var: c_int, valP: *mut c_double) -> c_int;
414
415 pub fn GRBgetconstrbyname(model: *mut GRBmodel, name: c_str, constrnumP: *mut c_int) -> c_int;
416
417 pub fn GRBgetconstrs(model: *mut GRBmodel, numnzP: *mut c_int, cbeg: *mut c_int, cind: *mut c_int,
418 cval: *mut c_double, start: c_int, len: c_int)
419 -> c_int;
420
421 pub fn GRBgetenv(model: *mut GRBmodel) -> *mut GRBenv;
422
423 pub fn GRBgetpwlobj(model: *mut GRBmodel, var: c_int, npointsP: *mut c_int, x: *mut c_double, y: *mut c_double)
424 -> c_int;
425
426 pub fn GRBgetq(model: *mut GRBmodel, numqnzP: *mut c_int, qrow: *mut c_int, qcol: *mut c_int, qval: *mut c_double)
427 -> c_int;
428
429 pub fn GRBgetqconstr(model: *mut GRBmodel, qconstr: c_int, numlnzP: *mut c_int, lind: *mut c_int,
430 lval: *mut c_double, numqnzP: *mut c_int, qrow: *mut c_int, qcol: *mut c_int,
431 qval: *mut c_double)
432 -> c_int;
433
434 pub fn GRBgetsos(model: *mut GRBmodel, nummembersP: *mut c_int, sostype: *mut c_int, beg: *mut c_int,
435 ind: *mut c_int, weight: *mut c_double, start: c_int, len: c_int)
436 -> c_int;
437
438 pub fn GRBgetvarbyname(model: *mut GRBmodel, name: c_str, varnumP: *mut c_int) -> c_int;
439
440 pub fn GRBgetvars(model: *mut GRBmodel, numnzP: *mut c_int, vbeg: *mut c_int, vind: *mut c_int,
441 vval: *mut c_double, start: c_int, len: c_int)
442 -> c_int;
443
444}
447
448extern "C" {
450 pub fn GRBreadmodel(env: *mut GRBenv, filename: c_str, modelP: *mut *mut GRBmodel) -> c_int;
451
452 pub fn GRBread(model: *mut GRBmodel, filename: c_str) -> c_int;
453
454 pub fn GRBwrite(model: *mut GRBmodel, filename: c_str) -> c_int;
455
456}
457
458extern "C" {
459 pub fn GRBgetattrinfo(model: *mut GRBmodel, attrname: c_str, datatypeP: *mut c_int, attrtypeP: *mut c_int,
460 settableP: *mut c_int)
461 -> c_int;
462}
463
464extern "C" {
465 pub fn GRBgetintattr(model: *mut GRBmodel, attrname: c_str, valueP: *mut c_int) -> c_int;
466
467 pub fn GRBgetdblattr(model: *mut GRBmodel, attrname: c_str, valueP: *mut c_double) -> c_int;
468
469 pub fn GRBgetstrattr(model: *mut GRBmodel, attrname: c_str, valueP: *mut c_str) -> c_int;
470
471
472 pub fn GRBsetintattr(model: *mut GRBmodel, attrname: c_str, value: c_int) -> c_int;
473
474 pub fn GRBsetdblattr(model: *mut GRBmodel, attrname: c_str, value: c_double) -> c_int;
475
476 pub fn GRBsetstrattr(model: *mut GRBmodel, attrname: c_str, value: c_str) -> c_int;
477}
478
479extern "C" {
480 pub fn GRBgetintattrelement(model: *mut GRBmodel, attrname: c_str, element: c_int, valueP: *mut c_int) -> c_int;
481
482 pub fn GRBgetdblattrelement(model: *mut GRBmodel, attrname: c_str, element: c_int, valueP: *mut c_double) -> c_int;
483
484 pub fn GRBgetcharattrelement(model: *mut GRBmodel, attrname: c_str, element: c_int, valueP: *mut c_char) -> c_int;
485
486 pub fn GRBgetstrattrelement(model: *mut GRBmodel, attrname: c_str, element: c_int, valueP: *mut c_str) -> c_int;
487
488
489 pub fn GRBsetintattrelement(model: *mut GRBmodel, attrname: c_str, element: c_int, value: c_int) -> c_int;
490
491 pub fn GRBsetdblattrelement(model: *mut GRBmodel, attrname: c_str, element: c_int, value: c_double) -> c_int;
492
493 pub fn GRBsetcharattrelement(model: *mut GRBmodel, attrname: c_str, element: c_int, value: c_char) -> c_int;
494
495 pub fn GRBsetstrattrelement(model: *mut GRBmodel, attrname: c_str, element: c_int, value: c_str) -> c_int;
496}
497
498extern "C" {
499 pub fn GRBgetintattrarray(model: *mut GRBmodel, attrname: c_str, first: c_int, len: c_int, values: *mut c_int)
500 -> c_int;
501
502 pub fn GRBgetdblattrarray(model: *mut GRBmodel, attrname: c_str, first: c_int, len: c_int, values: *mut c_double)
503 -> c_int;
504
505 pub fn GRBgetcharattrarray(model: *mut GRBmodel, attrname: c_str, first: c_int, len: c_int, values: *mut c_char)
506 -> c_int;
507
508 pub fn GRBgetstrattrarray(model: *mut GRBmodel, attrname: c_str, first: c_int, len: c_int, values: *mut c_str)
509 -> c_int;
510
511
512 pub fn GRBsetintattrarray(model: *mut GRBmodel, attrname: c_str, first: c_int, len: c_int, values: *const c_int)
513 -> c_int;
514
515 pub fn GRBsetdblattrarray(model: *mut GRBmodel, attrname: c_str, first: c_int, len: c_int, values: *const c_double)
516 -> c_int;
517
518 pub fn GRBsetcharattrarray(model: *mut GRBmodel, attrname: c_str, first: c_int, len: c_int, values: *const c_char)
519 -> c_int;
520
521 pub fn GRBsetstrattrarray(model: *mut GRBmodel, attrname: *const c_char, first: c_int, len: c_int,
522 values: *const c_str)
523 -> c_int;
524}
525
526extern "C" {
527 pub fn GRBgetintattrlist(model: *mut GRBmodel, attrname: c_str, len: c_int, ind: *const c_int, values: *mut c_int)
528 -> c_int;
529
530 pub fn GRBgetdblattrlist(model: *mut GRBmodel, attrname: c_str, len: c_int, ind: *const c_int,
531 values: *mut c_double)
532 -> c_int;
533
534 pub fn GRBgetcharattrlist(model: *mut GRBmodel, attrname: c_str, len: c_int, ind: *const c_int, values: *mut c_char)
535 -> c_int;
536
537 pub fn GRBgetstrattrlist(model: *mut GRBmodel, attrname: c_str, len: c_int, ind: *const c_int, values: *mut c_str)
538 -> c_int;
539
540
541 pub fn GRBsetintattrlist(model: *mut GRBmodel, attrname: c_str, len: c_int, ind: *const c_int, values: *const c_int)
542 -> c_int;
543
544 pub fn GRBsetdblattrlist(model: *mut GRBmodel, attrname: c_str, len: c_int, ind: *const c_int,
545 values: *const c_double)
546 -> c_int;
547
548 pub fn GRBsetcharattrlist(model: *mut GRBmodel, attrname: c_str, len: c_int, ind: *const c_int,
549 values: *const c_char)
550 -> c_int;
551
552 pub fn GRBsetstrattrlist(model: *mut GRBmodel, attrname: *const c_char, len: c_int, ind: *const c_int,
553 values: *const c_str)
554 -> c_int;
555}
556
557extern "C" {
559 pub fn GRBtunemodel(model: *mut GRBmodel) -> c_int;
560
561 pub fn GRBgettuneresult(model: *mut GRBmodel, n: c_int) -> c_int;
562
563 pub fn GRBgetdblparam(env: *mut GRBenv, paramname: c_str, value: *mut c_double) -> c_int;
564
565 pub fn GRBgetintparam(env: *mut GRBenv, paramname: c_str, value: *mut c_int) -> c_int;
566
567 pub fn GRBgetstrparam(env: *mut GRBenv, paramname: c_str, value: *mut c_char) -> c_int;
568
569 pub fn GRBsetdblparam(env: *mut GRBenv, paramname: c_str, value: c_double) -> c_int;
570
571 pub fn GRBsetintparam(env: *mut GRBenv, paramname: c_str, value: c_int) -> c_int;
572
573 pub fn GRBsetstrparam(env: *mut GRBenv, paramname: c_str, value: c_str) -> c_int;
574
575 pub fn GRBgetdblparaminfo(env: *mut GRBenv, paramname: c_str, valueP: *mut c_double, minP: *mut c_double,
576 maxP: *mut c_double, defaultP: *mut c_double)
577 -> c_int;
578
579 pub fn GRBgetintparaminfo(env: *mut GRBenv, paramname: c_str, valueP: *mut c_int, minP: *mut c_int,
580 maxP: *mut c_int, defaultP: *mut c_int)
581 -> c_int;
582
583 pub fn GRBgetstrparaminfo(env: *mut GRBenv, paramname: c_str, valueP: *mut c_char, defaultP: *mut c_char) -> c_int;
584
585 pub fn GRBreadparams(env: *mut GRBenv, filename: c_str) -> c_int;
586
587 pub fn GRBwriteparams(env: *mut GRBenv, filename: c_str) -> c_int;
588}
589
590extern "C" {
592 pub fn GRBmsg(env: *mut GRBenv, message: c_str);
593
594 pub fn GRBsetcallbackfunc(model: *mut GRBmodel,
595 cb: extern "C" fn(*mut GRBmodel, *mut c_void, c_int, *mut c_void) -> c_int,
596 usrdata: *mut c_void)
597 -> c_int;
598
599 pub fn GRBgetcallbackfunc(model: *mut GRBmodel,
600 cb: *mut extern "C" fn(*mut GRBmodel, *mut c_void, c_int, *mut c_void) -> c_int)
601 -> c_int;
602
603 pub fn GRBcbget(cbdata: *mut c_void, where_: c_int, what: c_int, resultP: *mut c_void) -> c_int;
604
605 pub fn GRBversion(majorP: *mut c_int, minorP: *mut c_int, technicalP: *mut c_int);
606}
607
608extern "C" {
610 pub fn GRBcbcut(cbdata: *mut c_void, cutlen: c_int, cutind: *const c_int, cutval: *const c_double,
611 cutsense: c_char, cutrhs: c_double)
612 -> c_int;
613
614 pub fn GRBcblazy(cbdata: *mut c_void, lazylen: c_int, lazyind: *const c_int, lazyval: *const c_double,
615 lazysense: c_char, lazyrhs: c_double)
616 -> c_int;
617
618 pub fn GRBcbsolution(cbdata: *mut c_void, solution: *const c_double) -> c_int;
619
620 pub fn GRBterminate(model: *mut GRBmodel);
621}
622
623extern "C" {
625 pub fn GRBgeterrormsg(env: *mut GRBenv) -> c_str;
626}
627
628extern "C" {
630 pub fn GRBFSolve(model: *mut GRBmodel, b: *mut GRBsvec, x: *mut GRBsvec) -> c_int;
631
632 pub fn GRBBSolve(model: *mut GRBmodel, b: *mut GRBsvec, x: *mut GRBsvec) -> c_int;
633
634 pub fn GRBBinvColj(model: *mut GRBmodel, j: c_int, x: *mut GRBsvec) -> c_int;
635
636 pub fn GRBBinvRowi(model: *mut GRBmodel, i: c_int, x: *mut GRBsvec) -> c_int;
637
638 pub fn GRBgetBasisHead(model: *mut GRBmodel, bhead: *mut c_int) -> c_int;
639}
640
641