KnapsackSolver.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.algorithms;
10 
63 public class KnapsackSolver {
64  private transient long swigCPtr;
65  protected transient boolean swigCMemOwn;
66 
67  protected KnapsackSolver(long cPtr, boolean cMemoryOwn) {
68  swigCMemOwn = cMemoryOwn;
69  swigCPtr = cPtr;
70  }
71 
72  protected static long getCPtr(KnapsackSolver obj) {
73  return (obj == null) ? 0 : obj.swigCPtr;
74  }
75 
76  @SuppressWarnings("deprecation")
77  protected void finalize() {
78  delete();
79  }
80 
81  public synchronized void delete() {
82  if (swigCPtr != 0) {
83  if (swigCMemOwn) {
84  swigCMemOwn = false;
85  mainJNI.delete_KnapsackSolver(swigCPtr);
86  }
87  swigCPtr = 0;
88  }
89  }
90 
91  public KnapsackSolver(String solver_name) {
92  this(mainJNI.new_KnapsackSolver__SWIG_0(solver_name), true);
93  }
94 
95  public KnapsackSolver(KnapsackSolver.SolverType solver_type, String solver_name) {
96  this(mainJNI.new_KnapsackSolver__SWIG_1(solver_type.swigValue(), solver_name), true);
97  }
98 
102  public void init(long[] profits, long[][] weights, long[] capacities) {
103  mainJNI.KnapsackSolver_init(swigCPtr, this, profits, weights, capacities);
104  }
105 
109  public long solve() {
110  return mainJNI.KnapsackSolver_solve(swigCPtr, this);
111  }
112 
116  public boolean bestSolutionContains(int item_id) {
117  return mainJNI.KnapsackSolver_bestSolutionContains(swigCPtr, this, item_id);
118  }
119 
123  public boolean isSolutionOptimal() {
124  return mainJNI.KnapsackSolver_isSolutionOptimal(swigCPtr, this);
125  }
126 
127  public String getName() {
128  return mainJNI.KnapsackSolver_getName(swigCPtr, this);
129  }
130 
131  public boolean useReduction() {
132  return mainJNI.KnapsackSolver_useReduction(swigCPtr, this);
133  }
134 
135  public void setUseReduction(boolean use_reduction) {
136  mainJNI.KnapsackSolver_setUseReduction(swigCPtr, this, use_reduction);
137  }
138 
145  public void setTimeLimit(double time_limit_seconds) {
146  mainJNI.KnapsackSolver_setTimeLimit(swigCPtr, this, time_limit_seconds);
147  }
148 
155  public enum SolverType {
164  KNAPSACK_BRUTE_FORCE_SOLVER(mainJNI.KnapsackSolver_KNAPSACK_BRUTE_FORCE_SOLVER_get()),
172  KNAPSACK_64ITEMS_SOLVER(mainJNI.KnapsackSolver_KNAPSACK_64ITEMS_SOLVER_get()),
180  KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER(mainJNI.KnapsackSolver_KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER_get()),
187  KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER(mainJNI.KnapsackSolver_KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER_get()),
194  KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER(mainJNI.KnapsackSolver_KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER_get());
195 
196  public final int swigValue() {
197  return swigValue;
198  }
199 
200  public static SolverType swigToEnum(int swigValue) {
201  SolverType[] swigValues = SolverType.class.getEnumConstants();
202  if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
203  return swigValues[swigValue];
204  for (SolverType swigEnum : swigValues)
205  if (swigEnum.swigValue == swigValue)
206  return swigEnum;
207  throw new IllegalArgumentException("No enum " + SolverType.class + " with value " + swigValue);
208  }
209 
210  @SuppressWarnings("unused")
211  private SolverType() {
212  this.swigValue = SwigNext.next++;
213  }
214 
215  @SuppressWarnings("unused")
216  private SolverType(int swigValue) {
217  this.swigValue = swigValue;
218  SwigNext.next = swigValue+1;
219  }
220 
221  @SuppressWarnings("unused")
222  private SolverType(SolverType swigEnum) {
223  this.swigValue = swigEnum.swigValue;
224  SwigNext.next = this.swigValue+1;
225  }
226 
227  private final int swigValue;
228 
229  private static class SwigNext {
230  private static int next = 0;
231  }
232  }
233 
234 }
long solve()
Solves the problem and returns the profit of the optimal solution.
void init(long[] profits, long[][] weights, long[] capacities)
Initializes the solver and enters the problem to be solved.
void setTimeLimit(double time_limit_seconds)
Time limit in seconds.
KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER
Dynamic Programming approach for single dimension problems Limited to one dimension,...
KNAPSACK_64ITEMS_SOLVER
Optimized method for single dimension small problems Limited to 64 items and one dimension,...
boolean bestSolutionContains(int item_id)
Returns true if the item 'item_id' is packed in the optimal knapsack.
Enum controlling which underlying algorithm is used.
This library solves knapsack problems.
KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER
CBC Based Solver This solver can deal with both large number of items and several dimensions.
KnapsackSolver(KnapsackSolver.SolverType solver_type, String solver_name)
KnapsackSolver(long cPtr, boolean cMemoryOwn)
boolean isSolutionOptimal()
Returns true if the solution was proven optimal.