Google OR-Tools v9.9
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
MPSolver.java
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2 * This file was automatically generated by SWIG (https://www.swig.org).
3 * Version 4.2.0
4 *
5 * Do not make changes to this file unless you know what you are doing - modify
6 * the SWIG interface file instead.
7 * ----------------------------------------------------------------------------- */
8
9package com.google.ortools.linearsolver;
10
11import java.lang.reflect.*;
12
17public class MPSolver {
18 private transient long swigCPtr;
19 protected transient boolean swigCMemOwn;
20
21 protected MPSolver(long cPtr, boolean cMemoryOwn) {
22 swigCMemOwn = cMemoryOwn;
23 swigCPtr = cPtr;
24 }
25
26 protected static long getCPtr(MPSolver obj) {
27 return (obj == null) ? 0 : obj.swigCPtr;
28 }
29
30 protected static long swigRelease(MPSolver obj) {
31 long ptr = 0;
32 if (obj != null) {
33 if (!obj.swigCMemOwn)
34 throw new RuntimeException("Cannot release ownership as memory is not owned");
35 ptr = obj.swigCPtr;
36 obj.swigCMemOwn = false;
37 obj.delete();
38 }
39 return ptr;
40 }
41
42 @SuppressWarnings({"deprecation", "removal"})
43 protected void finalize() {
44 delete();
45 }
46
47 public synchronized void delete() {
48 if (swigCPtr != 0) {
49 if (swigCMemOwn) {
50 swigCMemOwn = false;
51 mainJNI.delete_MPSolver(swigCPtr);
52 }
53 swigCPtr = 0;
54 }
55 }
56
60 public MPVariable[] makeVarArray(int count, double lb, double ub, boolean integer) {
61 MPVariable[] array = new MPVariable[count];
62 for (int i = 0; i < count; ++i) {
63 array[i] = makeVar(lb, ub, integer, "");
64 }
65 return array;
66 }
67
71 public MPVariable[] makeVarArray(int count, double lb, double ub, boolean integer,
72 String var_name) {
73 MPVariable[] array = new MPVariable[count];
74 for (int i = 0; i < count; ++i) {
75 array[i] = makeVar(lb, ub, integer, var_name + i);
76 }
77 return array;
78 }
79
80 public MPVariable[] makeNumVarArray(int count, double lb, double ub) {
81 return makeVarArray(count, lb, ub, false);
82 }
83
84 public MPVariable[] makeNumVarArray(int count, double lb, double ub, String var_name) {
85 return makeVarArray(count, lb, ub, false, var_name);
86 }
87
88 public MPVariable[] makeIntVarArray(int count, double lb, double ub) {
89 return makeVarArray(count, lb, ub, true);
90 }
91
92 public MPVariable[] makeIntVarArray(int count, double lb, double ub, String var_name) {
93 return makeVarArray(count, lb, ub, true, var_name);
94 }
95
96 public MPVariable[] makeBoolVarArray(int count) {
97 return makeVarArray(count, 0.0, 1.0, true);
98 }
99
100 public MPVariable[] makeBoolVarArray(int count, String var_name) {
101 return makeVarArray(count, 0.0, 1.0, true, var_name);
102 }
103
107 public MPSolver(String name, MPSolver.OptimizationProblemType problem_type) {
108 this(mainJNI.new_MPSolver(name, problem_type.swigValue()), true);
109 }
110
139 public static MPSolver createSolver(String solver_id) {
140 long cPtr = mainJNI.MPSolver_createSolver(solver_id);
141 return (cPtr == 0) ? null : new MPSolver(cPtr, true);
142 }
143
148 public static boolean supportsProblemType(MPSolver.OptimizationProblemType problem_type) {
149 return mainJNI.MPSolver_supportsProblemType(problem_type.swigValue());
150 }
151
152 public boolean isMip() {
153 return mainJNI.MPSolver_isMip(swigCPtr, this);
154 }
155
159 public MPSolver.OptimizationProblemType problemType() {
160 return MPSolver.OptimizationProblemType.swigToEnum(mainJNI.MPSolver_problemType(swigCPtr, this));
161 }
162
168 public void clear() {
169 mainJNI.MPSolver_clear(swigCPtr, this);
170 }
171
175 public int numVariables() {
176 return mainJNI.MPSolver_numVariables(swigCPtr, this);
177 }
178
184 return mainJNI.MPSolver_variables(swigCPtr, this);
185}
186
190 public MPVariable variable(int index) {
191 long cPtr = mainJNI.MPSolver_variable(swigCPtr, this, index);
192 return (cPtr == 0) ? null : new MPVariable(cPtr, false);
193 }
194
200 public MPVariable lookupVariableOrNull(String var_name) {
201 long cPtr = mainJNI.MPSolver_lookupVariableOrNull(swigCPtr, this, var_name);
202 return (cPtr == 0) ? null : new MPVariable(cPtr, false);
203 }
204
212 public MPVariable makeVar(double lb, double ub, boolean integer, String name) {
213 long cPtr = mainJNI.MPSolver_makeVar(swigCPtr, this, lb, ub, integer, name);
214 return (cPtr == 0) ? null : new MPVariable(cPtr, false);
215 }
216
220 public MPVariable makeNumVar(double lb, double ub, String name) {
221 long cPtr = mainJNI.MPSolver_makeNumVar(swigCPtr, this, lb, ub, name);
222 return (cPtr == 0) ? null : new MPVariable(cPtr, false);
223 }
224
228 public MPVariable makeIntVar(double lb, double ub, String name) {
229 long cPtr = mainJNI.MPSolver_makeIntVar(swigCPtr, this, lb, ub, name);
230 return (cPtr == 0) ? null : new MPVariable(cPtr, false);
231 }
232
236 public MPVariable makeBoolVar(String name) {
237 long cPtr = mainJNI.MPSolver_makeBoolVar(swigCPtr, this, name);
238 return (cPtr == 0) ? null : new MPVariable(cPtr, false);
239 }
240
244 public int numConstraints() {
245 return mainJNI.MPSolver_numConstraints(swigCPtr, this);
246 }
247
254 return mainJNI.MPSolver_constraints(swigCPtr, this);
255}
256
260 public MPConstraint constraint(int index) {
261 long cPtr = mainJNI.MPSolver_constraint(swigCPtr, this, index);
262 return (cPtr == 0) ? null : new MPConstraint(cPtr, false);
263 }
264
272 public MPConstraint lookupConstraintOrNull(String constraint_name) {
273 long cPtr = mainJNI.MPSolver_lookupConstraintOrNull(swigCPtr, this, constraint_name);
274 return (cPtr == 0) ? null : new MPConstraint(cPtr, false);
275 }
276
285 public MPConstraint makeConstraint(double lb, double ub) {
286 long cPtr = mainJNI.MPSolver_makeConstraint__SWIG_0(swigCPtr, this, lb, ub);
287 return (cPtr == 0) ? null : new MPConstraint(cPtr, false);
288 }
289
294 long cPtr = mainJNI.MPSolver_makeConstraint__SWIG_1(swigCPtr, this);
295 return (cPtr == 0) ? null : new MPConstraint(cPtr, false);
296 }
297
301 public MPConstraint makeConstraint(double lb, double ub, String name) {
302 long cPtr = mainJNI.MPSolver_makeConstraint__SWIG_2(swigCPtr, this, lb, ub, name);
303 return (cPtr == 0) ? null : new MPConstraint(cPtr, false);
304 }
305
309 public MPConstraint makeConstraint(String name) {
310 long cPtr = mainJNI.MPSolver_makeConstraint__SWIG_3(swigCPtr, this, name);
311 return (cPtr == 0) ? null : new MPConstraint(cPtr, false);
312 }
313
318 long cPtr = mainJNI.MPSolver_objective(swigCPtr, this);
319 return (cPtr == 0) ? null : new MPObjective(cPtr, false);
320 }
321
325 public MPSolver.ResultStatus solve() {
326 return MPSolver.ResultStatus.swigToEnum(mainJNI.MPSolver_solve__SWIG_0(swigCPtr, this));
327 }
328
332 public MPSolver.ResultStatus solve(MPSolverParameters param) {
333 return MPSolver.ResultStatus.swigToEnum(mainJNI.MPSolver_solve__SWIG_1(swigCPtr, this, MPSolverParameters.getCPtr(param), param));
334 }
335
340 public void write(String file_name) {
341 mainJNI.MPSolver_write(swigCPtr, this, file_name);
342 }
343
350 public double[] computeConstraintActivities() {
351 return mainJNI.MPSolver_computeConstraintActivities(swigCPtr, this);
352}
353
372 public boolean verifySolution(double tolerance, boolean log_errors) {
373 return mainJNI.MPSolver_verifySolution(swigCPtr, this, tolerance, log_errors);
374 }
375
384 public void reset() {
385 mainJNI.MPSolver_reset(swigCPtr, this);
386 }
387
398 public boolean interruptSolve() {
399 return mainJNI.MPSolver_interruptSolve(swigCPtr, this);
400 }
401
408 public boolean setSolverSpecificParametersAsString(String parameters) {
409 return mainJNI.MPSolver_setSolverSpecificParametersAsString(swigCPtr, this, parameters);
410 }
411
417 public static double infinity() {
418 return mainJNI.MPSolver_infinity();
419 }
420
424 public void enableOutput() {
425 mainJNI.MPSolver_enableOutput(swigCPtr, this);
426 }
427
431 public void suppressOutput() {
432 mainJNI.MPSolver_suppressOutput(swigCPtr, this);
433 }
434
438 public long iterations() {
439 return mainJNI.MPSolver_iterations(swigCPtr, this);
440 }
441
447 public long nodes() {
448 return mainJNI.MPSolver_nodes(swigCPtr, this);
449 }
450
454 public String solverVersion() {
455 return mainJNI.MPSolver_solverVersion(swigCPtr, this);
456 }
457
483 return mainJNI.MPSolver_computeExactConditionNumber(swigCPtr, this);
484 }
485
486 public void setTimeLimit(long time_limit_milliseconds) {
487 mainJNI.MPSolver_setTimeLimit(swigCPtr, this, time_limit_milliseconds);
488 }
489
490 public long wallTime() {
491 return mainJNI.MPSolver_wallTime(swigCPtr, this);
492 }
493
498 public String loadModelFromProto(com.google.ortools.linearsolver.MPModelProto input_model) {
499 return mainJNI.MPSolver_loadModelFromProto(swigCPtr, this, input_model.toByteArray());
500 }
501
506 public String loadModelFromProtoKeepNames(com.google.ortools.linearsolver.MPModelProto input_model) {
507 return mainJNI.MPSolver_loadModelFromProtoKeepNames(swigCPtr, this, input_model.toByteArray());
508 }
509
510 public String loadModelFromProtoWithUniqueNamesOrDie(com.google.ortools.linearsolver.MPModelProto input_model) {
511 return mainJNI.MPSolver_loadModelFromProtoWithUniqueNamesOrDie(swigCPtr, this, input_model.toByteArray());
512 }
513
518 byte[] buf = mainJNI.MPSolver_exportModelToProto(swigCPtr, this);
519 if (buf == null || buf.length == 0) {
520 return null;
521 }
522 try {
523 return com.google.ortools.linearsolver.MPModelProto.parseFrom(buf);
524 } catch (com.google.protobuf.InvalidProtocolBufferException e) {
525 throw new RuntimeException(
526 "Unable to parse com.google.ortools.linearsolver.MPModelProto protocol message.");
527 }
528}
529
534 byte[] buf = mainJNI.MPSolver_createSolutionResponseProto(swigCPtr, this);
535 if (buf == null || buf.length == 0) {
536 return null;
537 }
538 try {
539 return com.google.ortools.linearsolver.MPSolutionResponse.parseFrom(buf);
540 } catch (com.google.protobuf.InvalidProtocolBufferException e) {
541 throw new RuntimeException(
542 "Unable to parse com.google.ortools.linearsolver.MPSolutionResponse protocol message.");
543 }
544}
545
577 public boolean loadSolutionFromProto(com.google.ortools.linearsolver.MPSolutionResponse response) {
578 return mainJNI.MPSolver_loadSolutionFromProto(swigCPtr, this, response.toByteArray());
579 }
580
584 public static com.google.ortools.linearsolver.MPSolutionResponse solveWithProto(com.google.ortools.linearsolver.MPModelRequest model_request) {
585 byte[] buf = mainJNI.MPSolver_solveWithProto(model_request.toByteArray());
586 if (buf == null || buf.length == 0) {
587 return null;
588 }
589 try {
590 return com.google.ortools.linearsolver.MPSolutionResponse.parseFrom(buf);
591 } catch (com.google.protobuf.InvalidProtocolBufferException e) {
592 throw new RuntimeException(
593 "Unable to parse com.google.ortools.linearsolver.MPSolutionResponse protocol message.");
594 }
595}
596
601 return mainJNI.MPSolver_exportModelAsLpFormat__SWIG_0(swigCPtr, this, MPModelExportOptions.getCPtr(options), options);
602 }
603
607 public String exportModelAsLpFormat() {
608 return mainJNI.MPSolver_exportModelAsLpFormat__SWIG_1(swigCPtr, this);
609 }
610
615 return mainJNI.MPSolver_exportModelAsMpsFormat__SWIG_0(swigCPtr, this, MPModelExportOptions.getCPtr(options), options);
616 }
617
621 public String exportModelAsMpsFormat() {
622 return mainJNI.MPSolver_exportModelAsMpsFormat__SWIG_1(swigCPtr, this);
623 }
624
638 public void setHint(MPVariable[] variables, double[] values) {
639 mainJNI.MPSolver_setHint(swigCPtr, this, variables, values);
640 }
641
645 public boolean setNumThreads(int num_theads) {
646 return mainJNI.MPSolver_setNumThreads(swigCPtr, this, num_theads);
647 }
648
656 CLP_LINEAR_PROGRAMMING(mainJNI.MPSolver_CLP_LINEAR_PROGRAMMING_get()),
657 GLPK_LINEAR_PROGRAMMING(mainJNI.MPSolver_GLPK_LINEAR_PROGRAMMING_get()),
658 GLOP_LINEAR_PROGRAMMING(mainJNI.MPSolver_GLOP_LINEAR_PROGRAMMING_get()),
659 PDLP_LINEAR_PROGRAMMING(mainJNI.MPSolver_PDLP_LINEAR_PROGRAMMING_get()),
660 SCIP_MIXED_INTEGER_PROGRAMMING(mainJNI.MPSolver_SCIP_MIXED_INTEGER_PROGRAMMING_get()),
661 GLPK_MIXED_INTEGER_PROGRAMMING(mainJNI.MPSolver_GLPK_MIXED_INTEGER_PROGRAMMING_get()),
662 CBC_MIXED_INTEGER_PROGRAMMING(mainJNI.MPSolver_CBC_MIXED_INTEGER_PROGRAMMING_get()),
663 BOP_INTEGER_PROGRAMMING(mainJNI.MPSolver_BOP_INTEGER_PROGRAMMING_get()),
664 SAT_INTEGER_PROGRAMMING(mainJNI.MPSolver_SAT_INTEGER_PROGRAMMING_get()),
665 GUROBI_LINEAR_PROGRAMMING(mainJNI.MPSolver_GUROBI_LINEAR_PROGRAMMING_get()),
666 GUROBI_MIXED_INTEGER_PROGRAMMING(mainJNI.MPSolver_GUROBI_MIXED_INTEGER_PROGRAMMING_get()),
667 CPLEX_LINEAR_PROGRAMMING(mainJNI.MPSolver_CPLEX_LINEAR_PROGRAMMING_get()),
668 CPLEX_MIXED_INTEGER_PROGRAMMING(mainJNI.MPSolver_CPLEX_MIXED_INTEGER_PROGRAMMING_get()),
669 XPRESS_LINEAR_PROGRAMMING(mainJNI.MPSolver_XPRESS_LINEAR_PROGRAMMING_get()),
670 XPRESS_MIXED_INTEGER_PROGRAMMING(mainJNI.MPSolver_XPRESS_MIXED_INTEGER_PROGRAMMING_get());
671
672 public final int swigValue() {
673 return swigValue;
674 }
675
676 public static OptimizationProblemType swigToEnum(int swigValue) {
677 OptimizationProblemType[] swigValues = OptimizationProblemType.class.getEnumConstants();
678 if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
679 return swigValues[swigValue];
680 for (OptimizationProblemType swigEnum : swigValues)
681 if (swigEnum.swigValue == swigValue)
682 return swigEnum;
683 throw new IllegalArgumentException("No enum " + OptimizationProblemType.class + " with value " + swigValue);
684 }
685
686 @SuppressWarnings("unused")
687 private OptimizationProblemType() {
688 this.swigValue = SwigNext.next++;
689 }
690
691 @SuppressWarnings("unused")
692 private OptimizationProblemType(int swigValue) {
693 this.swigValue = swigValue;
694 SwigNext.next = swigValue+1;
695 }
696
697 @SuppressWarnings("unused")
698 private OptimizationProblemType(OptimizationProblemType swigEnum) {
699 this.swigValue = swigEnum.swigValue;
700 SwigNext.next = this.swigValue+1;
701 }
702
703 private final int swigValue;
704
705 private static class SwigNext {
706 private static int next = 0;
707 }
708 }
709
716 public enum ResultStatus {
744 NOT_SOLVED(mainJNI.MPSolver_NOT_SOLVED_get());
745
746 public final int swigValue() {
747 return swigValue;
748 }
749
750 public static ResultStatus swigToEnum(int swigValue) {
751 ResultStatus[] swigValues = ResultStatus.class.getEnumConstants();
752 if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
753 return swigValues[swigValue];
754 for (ResultStatus swigEnum : swigValues)
755 if (swigEnum.swigValue == swigValue)
756 return swigEnum;
757 throw new IllegalArgumentException("No enum " + ResultStatus.class + " with value " + swigValue);
758 }
759
760 @SuppressWarnings("unused")
761 private ResultStatus() {
762 this.swigValue = SwigNext.next++;
763 }
764
765 @SuppressWarnings("unused")
766 private ResultStatus(int swigValue) {
767 this.swigValue = swigValue;
768 SwigNext.next = swigValue+1;
769 }
770
771 @SuppressWarnings("unused")
772 private ResultStatus(ResultStatus swigEnum) {
773 this.swigValue = swigEnum.swigValue;
774 SwigNext.next = this.swigValue+1;
775 }
776
777 private final int swigValue;
778
779 private static class SwigNext {
780 private static int next = 0;
781 }
782 }
783
788 public enum BasisStatus {
789 FREE(mainJNI.MPSolver_FREE_get()),
794
795 public final int swigValue() {
796 return swigValue;
797 }
798
799 public static BasisStatus swigToEnum(int swigValue) {
800 BasisStatus[] swigValues = BasisStatus.class.getEnumConstants();
801 if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
802 return swigValues[swigValue];
803 for (BasisStatus swigEnum : swigValues)
804 if (swigEnum.swigValue == swigValue)
805 return swigEnum;
806 throw new IllegalArgumentException("No enum " + BasisStatus.class + " with value " + swigValue);
807 }
808
809 @SuppressWarnings("unused")
810 private BasisStatus() {
811 this.swigValue = SwigNext.next++;
812 }
813
814 @SuppressWarnings("unused")
815 private BasisStatus(int swigValue) {
816 this.swigValue = swigValue;
817 SwigNext.next = swigValue+1;
818 }
819
820 @SuppressWarnings("unused")
821 private BasisStatus(BasisStatus swigEnum) {
822 this.swigValue = swigEnum.swigValue;
823 SwigNext.next = this.swigValue+1;
824 }
825
826 private final int swigValue;
827
828 private static class SwigNext {
829 private static int next = 0;
830 }
831 }
832
833}
MPVariable[] makeIntVarArray(int count, double lb, double ub)
Definition MPSolver.java:88
String loadModelFromProtoWithUniqueNamesOrDie(com.google.ortools.linearsolver.MPModelProto input_model)
MPSolver(String name, MPSolver.OptimizationProblemType problem_type)
com.google.ortools.linearsolver.MPSolutionResponse createSolutionResponseProto()
MPConstraint makeConstraint(double lb, double ub, String name)
MPVariable makeNumVar(double lb, double ub, String name)
MPSolver.ResultStatus solve(MPSolverParameters param)
boolean setNumThreads(int num_theads)
MPVariable[] makeVarArray(int count, double lb, double ub, boolean integer, String var_name)
Definition MPSolver.java:71
boolean verifySolution(double tolerance, boolean log_errors)
MPConstraint makeConstraint(double lb, double ub)
boolean loadSolutionFromProto(com.google.ortools.linearsolver.MPSolutionResponse response)
static MPSolver createSolver(String solver_id)
boolean setSolverSpecificParametersAsString(String parameters)
static long getCPtr(MPSolver obj)
Definition MPSolver.java:26
void setTimeLimit(long time_limit_milliseconds)
MPVariable[] makeIntVarArray(int count, double lb, double ub, String var_name)
Definition MPSolver.java:92
String exportModelAsMpsFormat(MPModelExportOptions options)
MPVariable makeBoolVar(String name)
MPConstraint makeConstraint(String name)
MPVariable makeIntVar(double lb, double ub, String name)
String loadModelFromProtoKeepNames(com.google.ortools.linearsolver.MPModelProto input_model)
MPSolver(long cPtr, boolean cMemoryOwn)
Definition MPSolver.java:21
String exportModelAsLpFormat(MPModelExportOptions options)
void setHint(MPVariable[] variables, double[] values)
static long swigRelease(MPSolver obj)
Definition MPSolver.java:30
com.google.ortools.linearsolver.MPModelProto exportModelToProto()
MPSolver.OptimizationProblemType problemType()
String loadModelFromProto(com.google.ortools.linearsolver.MPModelProto input_model)
MPVariable[] makeBoolVarArray(int count)
Definition MPSolver.java:96
MPConstraint lookupConstraintOrNull(String constraint_name)
MPVariable[] makeVarArray(int count, double lb, double ub, boolean integer)
Definition MPSolver.java:60
MPVariable lookupVariableOrNull(String var_name)
MPVariable makeVar(double lb, double ub, boolean integer, String name)
MPVariable[] makeNumVarArray(int count, double lb, double ub, String var_name)
Definition MPSolver.java:84
MPVariable[] makeBoolVarArray(int count, String var_name)
static com.google.ortools.linearsolver.MPSolutionResponse solveWithProto(com.google.ortools.linearsolver.MPModelRequest model_request)
static boolean supportsProblemType(MPSolver.OptimizationProblemType problem_type)
MPVariable[] makeNumVarArray(int count, double lb, double ub)
Definition MPSolver.java:80
static BasisStatus swigToEnum(int swigValue)
static OptimizationProblemType swigToEnum(int swigValue)
static ResultStatus swigToEnum(int swigValue)