MPSolver.java
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2  * This file was automatically generated by SWIG (http://www.swig.org).
3  * Version 4.0.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 
9 package com.google.ortools.linearsolver;
10 
11 import java.lang.reflect.*;
12 
13 public class MPSolver {
14  private transient long swigCPtr;
15  protected transient boolean swigCMemOwn;
16 
17  protected MPSolver(long cPtr, boolean cMemoryOwn) {
18  swigCMemOwn = cMemoryOwn;
19  swigCPtr = cPtr;
20  }
21 
22  protected static long getCPtr(MPSolver obj) {
23  return (obj == null) ? 0 : obj.swigCPtr;
24  }
25 
26  @SuppressWarnings("deprecation")
27  protected void finalize() {
28  delete();
29  }
30 
31  public synchronized void delete() {
32  if (swigCPtr != 0) {
33  if (swigCMemOwn) {
34  swigCMemOwn = false;
36  }
37  swigCPtr = 0;
38  }
39  }
40 
41  public MPVariable[] makeVarArray(int count, double lb, double ub, boolean integer) {
42  MPVariable[] array = new MPVariable[count];
43  for (int i = 0; i < count; ++i) {
44  array[i] = makeVar(lb, ub, integer, "");
45  }
46  return array;
47  }
48 
49  public MPVariable[] makeVarArray(int count, double lb, double ub, boolean integer,
50  String var_name) {
51  MPVariable[] array = new MPVariable[count];
52  for (int i = 0; i < count; ++i) {
53  array[i] = makeVar(lb, ub, integer, var_name + i);
54  }
55  return array;
56  }
57 
58  public MPVariable[] makeNumVarArray(int count, double lb, double ub) {
59  return makeVarArray(count, lb, ub, false);
60  }
61 
62  public MPVariable[] makeNumVarArray(int count, double lb, double ub, String var_name) {
63  return makeVarArray(count, lb, ub, false, var_name);
64  }
65 
66  public MPVariable[] makeIntVarArray(int count, double lb, double ub) {
67  return makeVarArray(count, lb, ub, true);
68  }
69 
70  public MPVariable[] makeIntVarArray(int count, double lb, double ub, String var_name) {
71  return makeVarArray(count, lb, ub, true, var_name);
72  }
73 
74  public MPVariable[] makeBoolVarArray(int count) {
75  return makeVarArray(count, 0.0, 1.0, true);
76  }
77 
78  public MPVariable[] makeBoolVarArray(int count, String var_name) {
79  return makeVarArray(count, 0.0, 1.0, true, var_name);
80  }
81 
82  public MPSolver(String name, MPSolver.OptimizationProblemType problem_type) {
83  this(main_research_linear_solverJNI.new_MPSolver(name, problem_type.swigValue()), true);
84  }
85 
86  public static boolean supportsProblemType(MPSolver.OptimizationProblemType problem_type) {
87  return main_research_linear_solverJNI.MPSolver_supportsProblemType(problem_type.swigValue());
88  }
89 
90  public void clear() {
92  }
93 
94  public int numVariables() {
96  }
97 
98  public MPVariable[] variables() {
100 }
101 
102  public MPVariable lookupVariableOrNull(String var_name) {
103  long cPtr = main_research_linear_solverJNI.MPSolver_lookupVariableOrNull(swigCPtr, this, var_name);
104  return (cPtr == 0) ? null : new MPVariable(cPtr, false);
105  }
106 
107  public MPVariable makeVar(double lb, double ub, boolean integer, String name) {
108  long cPtr = main_research_linear_solverJNI.MPSolver_makeVar(swigCPtr, this, lb, ub, integer, name);
109  return (cPtr == 0) ? null : new MPVariable(cPtr, false);
110  }
111 
112  public MPVariable makeNumVar(double lb, double ub, String name) {
113  long cPtr = main_research_linear_solverJNI.MPSolver_makeNumVar(swigCPtr, this, lb, ub, name);
114  return (cPtr == 0) ? null : new MPVariable(cPtr, false);
115  }
116 
117  public MPVariable makeIntVar(double lb, double ub, String name) {
118  long cPtr = main_research_linear_solverJNI.MPSolver_makeIntVar(swigCPtr, this, lb, ub, name);
119  return (cPtr == 0) ? null : new MPVariable(cPtr, false);
120  }
121 
122  public MPVariable makeBoolVar(String name) {
123  long cPtr = main_research_linear_solverJNI.MPSolver_makeBoolVar(swigCPtr, this, name);
124  return (cPtr == 0) ? null : new MPVariable(cPtr, false);
125  }
126 
127  public int numConstraints() {
129  }
130 
133 }
134 
135  public MPConstraint lookupConstraintOrNull(String constraint_name) {
136  long cPtr = main_research_linear_solverJNI.MPSolver_lookupConstraintOrNull(swigCPtr, this, constraint_name);
137  return (cPtr == 0) ? null : new MPConstraint(cPtr, false);
138  }
139 
140  public MPConstraint makeConstraint(double lb, double ub) {
141  long cPtr = main_research_linear_solverJNI.MPSolver_makeConstraint__SWIG_0(swigCPtr, this, lb, ub);
142  return (cPtr == 0) ? null : new MPConstraint(cPtr, false);
143  }
144 
147  return (cPtr == 0) ? null : new MPConstraint(cPtr, false);
148  }
149 
150  public MPConstraint makeConstraint(double lb, double ub, String name) {
151  long cPtr = main_research_linear_solverJNI.MPSolver_makeConstraint__SWIG_2(swigCPtr, this, lb, ub, name);
152  return (cPtr == 0) ? null : new MPConstraint(cPtr, false);
153  }
154 
155  public MPConstraint makeConstraint(String name) {
156  long cPtr = main_research_linear_solverJNI.MPSolver_makeConstraint__SWIG_3(swigCPtr, this, name);
157  return (cPtr == 0) ? null : new MPConstraint(cPtr, false);
158  }
159 
161  long cPtr = main_research_linear_solverJNI.MPSolver_objective(swigCPtr, this);
162  return (cPtr == 0) ? null : new MPObjective(cPtr, false);
163  }
164 
167  }
168 
171  }
172 
173  public double[] computeConstraintActivities() {
175 }
176 
177  public boolean verifySolution(double tolerance, boolean log_errors) {
178  return main_research_linear_solverJNI.MPSolver_verifySolution(swigCPtr, this, tolerance, log_errors);
179  }
180 
181  public void reset() {
183  }
184 
185  public boolean interruptSolve() {
187  }
188 
189  public SWIGTYPE_p_util__Status loadSolutionFromProto(SWIGTYPE_p_operations_research__MPSolutionResponse response, double tolerance) {
190  return new SWIGTYPE_p_util__Status(main_research_linear_solverJNI.MPSolver_loadSolutionFromProto__SWIG_0(swigCPtr, this, SWIGTYPE_p_operations_research__MPSolutionResponse.getCPtr(response), tolerance), true);
191  }
192 
193  public SWIGTYPE_p_util__Status loadSolutionFromProto(SWIGTYPE_p_operations_research__MPSolutionResponse response) {
194  return new SWIGTYPE_p_util__Status(main_research_linear_solverJNI.MPSolver_loadSolutionFromProto__SWIG_1(swigCPtr, this, SWIGTYPE_p_operations_research__MPSolutionResponse.getCPtr(response)), true);
195  }
196 
197  public boolean setSolverSpecificParametersAsString(String parameters) {
199  }
200 
201  public static double infinity() {
203  }
204 
205  public void enableOutput() {
207  }
208 
209  public void suppressOutput() {
211  }
212 
213  public long iterations() {
215  }
216 
217  public long nodes() {
218  return main_research_linear_solverJNI.MPSolver_nodes(swigCPtr, this);
219  }
220 
221  public double computeExactConditionNumber() {
223  }
224 
225  public void setTimeLimit(long time_limit_milliseconds) {
226  main_research_linear_solverJNI.MPSolver_setTimeLimit(swigCPtr, this, time_limit_milliseconds);
227  }
228 
229  public long wallTime() {
230  return main_research_linear_solverJNI.MPSolver_wallTime(swigCPtr, this);
231  }
232 
234  return main_research_linear_solverJNI.MPSolver_loadModelFromProto(swigCPtr, this, input_model.toByteArray());
235  }
236 
238  return main_research_linear_solverJNI.MPSolver_loadModelFromProtoWithUniqueNamesOrDie(swigCPtr, this, input_model.toByteArray());
239  }
240 
242  byte[] buf = main_research_linear_solverJNI.MPSolver_exportModelToProto(swigCPtr, this);
243  if (buf == null || buf.length == 0) {
244  return null;
245  }
246  try {
248  } catch (com.google.protobuf.InvalidProtocolBufferException e) {
249  throw new RuntimeException(
250  "Unable to parse com.google.ortools.linearsolver.MPModelProto protocol message.");
251  }
252 }
253 
256  if (buf == null || buf.length == 0) {
257  return null;
258  }
259  try {
261  } catch (com.google.protobuf.InvalidProtocolBufferException e) {
262  throw new RuntimeException(
263  "Unable to parse com.google.ortools.linearsolver.MPSolutionResponse protocol message.");
264  }
265 }
266 
268  byte[] buf = main_research_linear_solverJNI.MPSolver_solveWithProto(model_request.toByteArray());
269  if (buf == null || buf.length == 0) {
270  return null;
271  }
272  try {
274  } catch (com.google.protobuf.InvalidProtocolBufferException e) {
275  throw new RuntimeException(
276  "Unable to parse com.google.ortools.linearsolver.MPSolutionResponse protocol message.");
277  }
278 }
279 
281  return main_research_linear_solverJNI.MPSolver_exportModelAsLpFormat__SWIG_0(swigCPtr, this, MPModelExportOptions.getCPtr(options), options);
282  }
283 
284  public String exportModelAsLpFormat() {
286  }
287 
289  return main_research_linear_solverJNI.MPSolver_exportModelAsMpsFormat__SWIG_0(swigCPtr, this, MPModelExportOptions.getCPtr(options), options);
290  }
291 
292  public String exportModelAsMpsFormat() {
294  }
295 
299  public void setHint(MPVariable[] variables, double[] values) {
301  }
302 
306  public boolean setNumThreads(int num_theads) {
307  return main_research_linear_solverJNI.MPSolver_setNumThreads(swigCPtr, this, num_theads);
308  }
309 
315 
316  public final int swigValue() {
317  return swigValue;
318  }
319 
320  public static OptimizationProblemType swigToEnum(int swigValue) {
321  OptimizationProblemType[] swigValues = OptimizationProblemType.class.getEnumConstants();
322  if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
323  return swigValues[swigValue];
324  for (OptimizationProblemType swigEnum : swigValues)
325  if (swigEnum.swigValue == swigValue)
326  return swigEnum;
327  throw new IllegalArgumentException("No enum " + OptimizationProblemType.class + " with value " + swigValue);
328  }
329 
330  @SuppressWarnings("unused")
331  private OptimizationProblemType() {
332  this.swigValue = SwigNext.next++;
333  }
334 
335  @SuppressWarnings("unused")
336  private OptimizationProblemType(int swigValue) {
337  this.swigValue = swigValue;
338  SwigNext.next = swigValue+1;
339  }
340 
341  @SuppressWarnings("unused")
342  private OptimizationProblemType(OptimizationProblemType swigEnum) {
343  this.swigValue = swigEnum.swigValue;
344  SwigNext.next = this.swigValue+1;
345  }
346 
347  private final int swigValue;
348 
349  private static class SwigNext {
350  private static int next = 0;
351  }
352  }
353 
354  public enum ResultStatus {
361 
362  public final int swigValue() {
363  return swigValue;
364  }
365 
366  public static ResultStatus swigToEnum(int swigValue) {
367  ResultStatus[] swigValues = ResultStatus.class.getEnumConstants();
368  if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
369  return swigValues[swigValue];
370  for (ResultStatus swigEnum : swigValues)
371  if (swigEnum.swigValue == swigValue)
372  return swigEnum;
373  throw new IllegalArgumentException("No enum " + ResultStatus.class + " with value " + swigValue);
374  }
375 
376  @SuppressWarnings("unused")
377  private ResultStatus() {
378  this.swigValue = SwigNext.next++;
379  }
380 
381  @SuppressWarnings("unused")
382  private ResultStatus(int swigValue) {
383  this.swigValue = swigValue;
384  SwigNext.next = swigValue+1;
385  }
386 
387  @SuppressWarnings("unused")
388  private ResultStatus(ResultStatus swigEnum) {
389  this.swigValue = swigEnum.swigValue;
390  SwigNext.next = this.swigValue+1;
391  }
392 
393  private final int swigValue;
394 
395  private static class SwigNext {
396  private static int next = 0;
397  }
398  }
399 
400  public enum BasisStatus {
402  AT_LOWER_BOUND,
403  AT_UPPER_BOUND,
404  FIXED_VALUE,
405  BASIC;
406 
407  public final int swigValue() {
408  return swigValue;
409  }
410 
411  public static BasisStatus swigToEnum(int swigValue) {
412  BasisStatus[] swigValues = BasisStatus.class.getEnumConstants();
413  if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
414  return swigValues[swigValue];
415  for (BasisStatus swigEnum : swigValues)
416  if (swigEnum.swigValue == swigValue)
417  return swigEnum;
418  throw new IllegalArgumentException("No enum " + BasisStatus.class + " with value " + swigValue);
419  }
420 
421  @SuppressWarnings("unused")
422  private BasisStatus() {
423  this.swigValue = SwigNext.next++;
424  }
425 
426  @SuppressWarnings("unused")
427  private BasisStatus(int swigValue) {
428  this.swigValue = swigValue;
429  SwigNext.next = swigValue+1;
430  }
431 
432  @SuppressWarnings("unused")
433  private BasisStatus(BasisStatus swigEnum) {
434  this.swigValue = swigEnum.swigValue;
435  SwigNext.next = this.swigValue+1;
436  }
437 
438  private final int swigValue;
439 
440  private static class SwigNext {
441  private static int next = 0;
442  }
443  }
444 
445 }
static final native long MPSolver_iterations(long jarg1, MPSolver jarg1_)
static final native int MPSolver_solve__SWIG_0(long jarg1, MPSolver jarg1_)
com.google.ortools.linearsolver.MPSolutionResponse createSolutionResponseProto()
Definition: MPSolver.java:254
static final native void MPSolver_suppressOutput(long jarg1, MPSolver jarg1_)
static final native int MPSolver_numConstraints(long jarg1, MPSolver jarg1_)
static final native long MPSolver_makeConstraint__SWIG_1(long jarg1, MPSolver jarg1_)
com.google.ortools.linearsolver.MPModelProto exportModelToProto()
Definition: MPSolver.java:241
static final native String MPSolver_loadModelFromProtoWithUniqueNamesOrDie(long jarg1, MPSolver jarg1_, byte[] jarg2)
static com.google.ortools.linearsolver.MPSolutionResponse parseFrom(java.nio.ByteBuffer data)
MPVariable [] makeVarArray(int count, double lb, double ub, boolean integer, String var_name)
Definition: MPSolver.java:49
MPVariable [] makeNumVarArray(int count, double lb, double ub, String var_name)
Definition: MPSolver.java:62
boolean setNumThreads(int num_theads)
Sets the number of threads to be used by the solver.
Definition: MPSolver.java:306
static final native MPVariable [] MPSolver_variables(long jarg1, MPSolver jarg1_)
MPVariable makeIntVar(double lb, double ub, String name)
Definition: MPSolver.java:117
static final native byte [] MPSolver_exportModelToProto(long jarg1, MPSolver jarg1_)
String loadModelFromProtoWithUniqueNamesOrDie(com.google.ortools.linearsolver.MPModelProto input_model)
Definition: MPSolver.java:237
SWIGTYPE_p_util__Status loadSolutionFromProto(SWIGTYPE_p_operations_research__MPSolutionResponse response, double tolerance)
Definition: MPSolver.java:189
void setHint(MPVariable[] variables, double[] values)
Sets a hint for solution.
Definition: MPSolver.java:299
MPConstraint makeConstraint(String name)
Definition: MPSolver.java:155
static final native long MPSolver_makeConstraint__SWIG_0(long jarg1, MPSolver jarg1_, double jarg2, double jarg3)
MPConstraint makeConstraint(double lb, double ub, String name)
Definition: MPSolver.java:150
static final native String MPSolver_loadModelFromProto(long jarg1, MPSolver jarg1_, byte[] jarg2)
void setTimeLimit(long time_limit_milliseconds)
Definition: MPSolver.java:225
MPVariable [] makeBoolVarArray(int count)
Definition: MPSolver.java:74
static final native String MPSolver_exportModelAsLpFormat__SWIG_1(long jarg1, MPSolver jarg1_)
String exportModelAsLpFormat(MPModelExportOptions options)
Definition: MPSolver.java:280
static final native boolean MPSolver_supportsProblemType(int jarg1)
static final native long MPSolver_makeIntVar(long jarg1, MPSolver jarg1_, double jarg2, double jarg3, String jarg4)
static final native boolean MPSolver_setSolverSpecificParametersAsString(long jarg1, MPSolver jarg1_, String jarg2)
static com.google.ortools.linearsolver.MPSolutionResponse solveWithProto(com.google.ortools.linearsolver.MPModelRequest model_request)
Definition: MPSolver.java:267
static BasisStatus swigToEnum(int swigValue)
Definition: MPSolver.java:411
static final native long MPSolver_loadSolutionFromProto__SWIG_0(long jarg1, MPSolver jarg1_, long jarg2, double jarg3)
MPVariable [] makeIntVarArray(int count, double lb, double ub)
Definition: MPSolver.java:66
MPVariable [] makeVarArray(int count, double lb, double ub, boolean integer)
Definition: MPSolver.java:41
static final native void MPSolver_setHint(long jarg1, MPSolver jarg1_, MPVariable[] jarg2, double[] jarg3)
static final native byte [] MPSolver_solveWithProto(byte[] jarg1)
SWIGTYPE_p_util__Status loadSolutionFromProto(SWIGTYPE_p_operations_research__MPSolutionResponse response)
Definition: MPSolver.java:193
static final native String MPSolver_exportModelAsMpsFormat__SWIG_1(long jarg1, MPSolver jarg1_)
static final native void MPSolver_setTimeLimit(long jarg1, MPSolver jarg1_, long jarg2)
MPConstraint makeConstraint(double lb, double ub)
Definition: MPSolver.java:140
static final native int MPSolver_solve__SWIG_1(long jarg1, MPSolver jarg1_, long jarg2, MPSolverParameters jarg2_)
MPSolver(long cPtr, boolean cMemoryOwn)
Definition: MPSolver.java:17
static final native long MPSolver_makeConstraint__SWIG_2(long jarg1, MPSolver jarg1_, double jarg2, double jarg3, String jarg4)
MPVariable [] makeBoolVarArray(int count, String var_name)
Definition: MPSolver.java:78
MPSolver(String name, MPSolver.OptimizationProblemType problem_type)
Definition: MPSolver.java:82
static final native void MPSolver_reset(long jarg1, MPSolver jarg1_)
MPVariable [] makeIntVarArray(int count, double lb, double ub, String var_name)
Definition: MPSolver.java:70
MPSolver.ResultStatus solve(MPSolverParameters param)
Definition: MPSolver.java:169
static final native boolean MPSolver_setNumThreads(long jarg1, MPSolver jarg1_, int jarg2)
String exportModelAsMpsFormat(MPModelExportOptions options)
Definition: MPSolver.java:288
static final native MPConstraint [] MPSolver_constraints(long jarg1, MPSolver jarg1_)
static ResultStatus swigToEnum(int swigValue)
Definition: MPSolver.java:366
static final native long MPSolver_makeBoolVar(long jarg1, MPSolver jarg1_, String jarg2)
static boolean supportsProblemType(MPSolver.OptimizationProblemType problem_type)
Definition: MPSolver.java:86
static final native String MPSolver_exportModelAsMpsFormat__SWIG_0(long jarg1, MPSolver jarg1_, long jarg2, MPModelExportOptions jarg2_)
MPVariable makeVar(double lb, double ub, boolean integer, String name)
Definition: MPSolver.java:107
static final native void MPSolver_enableOutput(long jarg1, MPSolver jarg1_)
boolean setSolverSpecificParametersAsString(String parameters)
Definition: MPSolver.java:197
boolean verifySolution(double tolerance, boolean log_errors)
Definition: MPSolver.java:177
static final native long MPSolver_objective(long jarg1, MPSolver jarg1_)
String loadModelFromProto(com.google.ortools.linearsolver.MPModelProto input_model)
Definition: MPSolver.java:233
static final native boolean MPSolver_verifySolution(long jarg1, MPSolver jarg1_, double jarg2, boolean jarg3)
static final native long MPSolver_loadSolutionFromProto__SWIG_1(long jarg1, MPSolver jarg1_, long jarg2)
static final native long MPSolver_makeConstraint__SWIG_3(long jarg1, MPSolver jarg1_, String jarg2)
MPVariable makeNumVar(double lb, double ub, String name)
Definition: MPSolver.java:112
MPConstraint lookupConstraintOrNull(String constraint_name)
Definition: MPSolver.java:135
static final native long MPSolver_wallTime(long jarg1, MPSolver jarg1_)
static final native long new_MPSolver(String jarg1, int jarg2)
MPVariable [] makeNumVarArray(int count, double lb, double ub)
Definition: MPSolver.java:58
MPVariable makeBoolVar(String name)
Definition: MPSolver.java:122
static final native long MPSolver_lookupVariableOrNull(long jarg1, MPSolver jarg1_, String jarg2)
static final native long MPSolver_makeVar(long jarg1, MPSolver jarg1_, double jarg2, double jarg3, boolean jarg4, String jarg5)
static final native double [] MPSolver_computeConstraintActivities(long jarg1, MPSolver jarg1_)
static final native void MPSolver_clear(long jarg1, MPSolver jarg1_)
static final native long MPSolver_lookupConstraintOrNull(long jarg1, MPSolver jarg1_, String jarg2)
static OptimizationProblemType swigToEnum(int swigValue)
Definition: MPSolver.java:320
static final native String MPSolver_exportModelAsLpFormat__SWIG_0(long jarg1, MPSolver jarg1_, long jarg2, MPModelExportOptions jarg2_)
static com.google.ortools.linearsolver.MPModelProto parseFrom(java.nio.ByteBuffer data)
static final native int MPSolver_numVariables(long jarg1, MPSolver jarg1_)
MPVariable lookupVariableOrNull(String var_name)
Definition: MPSolver.java:102
static final native void delete_MPSolver(long jarg1)
static final native long MPSolver_nodes(long jarg1, MPSolver jarg1_)
static final native boolean MPSolver_interruptSolve(long jarg1, MPSolver jarg1_)
static final native long MPSolver_makeNumVar(long jarg1, MPSolver jarg1_, double jarg2, double jarg3, String jarg4)
static final native double MPSolver_computeExactConditionNumber(long jarg1, MPSolver jarg1_)
static final native byte [] MPSolver_createSolutionResponseProto(long jarg1, MPSolver jarg1_)