Google OR-Tools v9.15
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.4.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
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
326 return MPSolver.ResultStatus.swigToEnum(mainJNI.MPSolver_solve__SWIG_0(swigCPtr, this));
327 }
328
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
493 public long wallTime() {
494 return mainJNI.MPSolver_wallTime(swigCPtr, this);
495 }
496
501 public String loadModelFromProto(com.google.ortools.linearsolver.MPModelProto input_model) {
502 return mainJNI.MPSolver_loadModelFromProto(swigCPtr, this, input_model.toByteArray());
503 }
504
509 public String loadModelFromProtoKeepNames(com.google.ortools.linearsolver.MPModelProto input_model) {
510 return mainJNI.MPSolver_loadModelFromProtoKeepNames(swigCPtr, this, input_model.toByteArray());
511 }
512
513 public String loadModelFromProtoWithUniqueNamesOrDie(com.google.ortools.linearsolver.MPModelProto input_model) {
514 return mainJNI.MPSolver_loadModelFromProtoWithUniqueNamesOrDie(swigCPtr, this, input_model.toByteArray());
515 }
516
521 byte[] buf = mainJNI.MPSolver_exportModelToProto(swigCPtr, this);
522 if (buf == null || buf.length == 0) {
523 return null;
524 }
525 try {
526 return com.google.ortools.linearsolver.MPModelProto.parseFrom(buf);
527 } catch (com.google.protobuf.InvalidProtocolBufferException e) {
528 throw new RuntimeException(
529 "Unable to parse com.google.ortools.linearsolver.MPModelProto protocol message.");
530 }
531}
532
537 byte[] buf = mainJNI.MPSolver_createSolutionResponseProto(swigCPtr, this);
538 if (buf == null || buf.length == 0) {
539 return null;
540 }
541 try {
542 return com.google.ortools.linearsolver.MPSolutionResponse.parseFrom(buf);
543 } catch (com.google.protobuf.InvalidProtocolBufferException e) {
544 throw new RuntimeException(
545 "Unable to parse com.google.ortools.linearsolver.MPSolutionResponse protocol message.");
546 }
547}
548
580 public boolean loadSolutionFromProto(com.google.ortools.linearsolver.MPSolutionResponse response) {
581 return mainJNI.MPSolver_loadSolutionFromProto(swigCPtr, this, response.toByteArray());
582 }
583
587 public static com.google.ortools.linearsolver.MPSolutionResponse solveWithProto(com.google.ortools.linearsolver.MPModelRequest model_request) {
588 byte[] buf = mainJNI.MPSolver_solveWithProto(model_request.toByteArray());
589 if (buf == null || buf.length == 0) {
590 return null;
591 }
592 try {
593 return com.google.ortools.linearsolver.MPSolutionResponse.parseFrom(buf);
594 } catch (com.google.protobuf.InvalidProtocolBufferException e) {
595 throw new RuntimeException(
596 "Unable to parse com.google.ortools.linearsolver.MPSolutionResponse protocol message.");
597 }
598}
599
603 public String exportModelAsLpFormat(boolean obfuscate) {
604 return mainJNI.MPSolver_exportModelAsLpFormat__SWIG_0(swigCPtr, this, obfuscate);
605 }
606
610 public String exportModelAsLpFormat() {
611 return mainJNI.MPSolver_exportModelAsLpFormat__SWIG_1(swigCPtr, this);
612 }
613
617 public String exportModelAsMpsFormat(boolean fixed_format, boolean obfuscate) {
618 return mainJNI.MPSolver_exportModelAsMpsFormat(swigCPtr, this, fixed_format, obfuscate);
619 }
620
624 public boolean writeModelToMpsFile(String filename, boolean fixed_format, boolean obfuscate) {
625 return mainJNI.MPSolver_writeModelToMpsFile(swigCPtr, this, filename, fixed_format, obfuscate);
626 }
627
641 public void setHint(MPVariable[] variables, double[] values) {
642 mainJNI.MPSolver_setHint(swigCPtr, this, variables, values);
643 }
644
648 public boolean setNumThreads(int num_theads) {
649 return mainJNI.MPSolver_setNumThreads(swigCPtr, this, num_theads);
650 }
651
658 public enum OptimizationProblemType {
659 CLP_LINEAR_PROGRAMMING(mainJNI.MPSolver_CLP_LINEAR_PROGRAMMING_get()),
660 GLPK_LINEAR_PROGRAMMING(mainJNI.MPSolver_GLPK_LINEAR_PROGRAMMING_get()),
661 GLOP_LINEAR_PROGRAMMING(mainJNI.MPSolver_GLOP_LINEAR_PROGRAMMING_get()),
662 PDLP_LINEAR_PROGRAMMING(mainJNI.MPSolver_PDLP_LINEAR_PROGRAMMING_get()),
663 SCIP_MIXED_INTEGER_PROGRAMMING(mainJNI.MPSolver_SCIP_MIXED_INTEGER_PROGRAMMING_get()),
664 GLPK_MIXED_INTEGER_PROGRAMMING(mainJNI.MPSolver_GLPK_MIXED_INTEGER_PROGRAMMING_get()),
665 CBC_MIXED_INTEGER_PROGRAMMING(mainJNI.MPSolver_CBC_MIXED_INTEGER_PROGRAMMING_get()),
666 BOP_INTEGER_PROGRAMMING(mainJNI.MPSolver_BOP_INTEGER_PROGRAMMING_get()),
667 SAT_INTEGER_PROGRAMMING(mainJNI.MPSolver_SAT_INTEGER_PROGRAMMING_get()),
668 GUROBI_LINEAR_PROGRAMMING(mainJNI.MPSolver_GUROBI_LINEAR_PROGRAMMING_get()),
669 GUROBI_MIXED_INTEGER_PROGRAMMING(mainJNI.MPSolver_GUROBI_MIXED_INTEGER_PROGRAMMING_get()),
670 CPLEX_LINEAR_PROGRAMMING(mainJNI.MPSolver_CPLEX_LINEAR_PROGRAMMING_get()),
671 CPLEX_MIXED_INTEGER_PROGRAMMING(mainJNI.MPSolver_CPLEX_MIXED_INTEGER_PROGRAMMING_get()),
672 XPRESS_LINEAR_PROGRAMMING(mainJNI.MPSolver_XPRESS_LINEAR_PROGRAMMING_get()),
673 XPRESS_MIXED_INTEGER_PROGRAMMING(mainJNI.MPSolver_XPRESS_MIXED_INTEGER_PROGRAMMING_get());
674
675 public final int swigValue() {
676 return swigValue;
677 }
678
679 public static OptimizationProblemType swigToEnum(int swigValue) {
680 OptimizationProblemType[] swigValues = OptimizationProblemType.class.getEnumConstants();
681 if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
682 return swigValues[swigValue];
683 for (OptimizationProblemType swigEnum : swigValues)
684 if (swigEnum.swigValue == swigValue)
685 return swigEnum;
686 throw new IllegalArgumentException("No enum " + OptimizationProblemType.class + " with value " + swigValue);
687 }
688
689 @SuppressWarnings("unused")
690 private OptimizationProblemType() {
691 this.swigValue = SwigNext.next++;
692 }
693
694 @SuppressWarnings("unused")
695 private OptimizationProblemType(int swigValue) {
696 this.swigValue = swigValue;
697 SwigNext.next = swigValue+1;
698 }
699
700 @SuppressWarnings("unused")
701 private OptimizationProblemType(OptimizationProblemType swigEnum) {
702 this.swigValue = swigEnum.swigValue;
703 SwigNext.next = this.swigValue+1;
704 }
705
706 private final int swigValue;
707
708 private static class SwigNext {
709 private static int next = 0;
710 }
711 }
712
719 public enum ResultStatus {
747 NOT_SOLVED(mainJNI.MPSolver_NOT_SOLVED_get());
748
749 public final int swigValue() {
750 return swigValue;
751 }
752
753 public static ResultStatus swigToEnum(int swigValue) {
754 ResultStatus[] swigValues = ResultStatus.class.getEnumConstants();
755 if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
756 return swigValues[swigValue];
757 for (ResultStatus swigEnum : swigValues)
758 if (swigEnum.swigValue == swigValue)
759 return swigEnum;
760 throw new IllegalArgumentException("No enum " + ResultStatus.class + " with value " + swigValue);
761 }
762
763 @SuppressWarnings("unused")
764 private ResultStatus() {
765 this.swigValue = SwigNext.next++;
766 }
767
768 @SuppressWarnings("unused")
769 private ResultStatus(int swigValue) {
770 this.swigValue = swigValue;
771 SwigNext.next = swigValue+1;
772 }
773
774 @SuppressWarnings("unused")
775 private ResultStatus(ResultStatus swigEnum) {
776 this.swigValue = swigEnum.swigValue;
777 SwigNext.next = this.swigValue+1;
778 }
779
780 private final int swigValue;
781
782 private static class SwigNext {
783 private static int next = 0;
784 }
785 }
786
791 public enum BasisStatus {
792 FREE(mainJNI.MPSolver_FREE_get()),
797
798 public final int swigValue() {
799 return swigValue;
800 }
801
802 public static BasisStatus swigToEnum(int swigValue) {
803 BasisStatus[] swigValues = BasisStatus.class.getEnumConstants();
804 if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
805 return swigValues[swigValue];
806 for (BasisStatus swigEnum : swigValues)
807 if (swigEnum.swigValue == swigValue)
808 return swigEnum;
809 throw new IllegalArgumentException("No enum " + BasisStatus.class + " with value " + swigValue);
810 }
811
812 @SuppressWarnings("unused")
813 private BasisStatus() {
814 this.swigValue = SwigNext.next++;
815 }
816
817 @SuppressWarnings("unused")
818 private BasisStatus(int swigValue) {
819 this.swigValue = swigValue;
820 SwigNext.next = swigValue+1;
821 }
822
823 @SuppressWarnings("unused")
824 private BasisStatus(BasisStatus swigEnum) {
825 this.swigValue = swigEnum.swigValue;
826 SwigNext.next = this.swigValue+1;
827 }
828
829 private final int swigValue;
830
831 private static class SwigNext {
832 private static int next = 0;
833 }
834 }
835
836}
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
MPVariable makeBoolVar(String name)
MPConstraint makeConstraint(String name)
MPVariable makeIntVar(double lb, double ub, String name)
String exportModelAsMpsFormat(boolean fixed_format, boolean obfuscate)
String loadModelFromProtoKeepNames(com.google.ortools.linearsolver.MPModelProto input_model)
MPSolver(long cPtr, boolean cMemoryOwn)
Definition MPSolver.java:21
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)
boolean writeModelToMpsFile(String filename, boolean fixed_format, boolean obfuscate)
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
String exportModelAsLpFormat(boolean obfuscate)
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)