Java Reference

Java Reference

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 
97 public class KnapsackSolver {
98  private transient long swigCPtr;
99  protected transient boolean swigCMemOwn;
100 
101  protected KnapsackSolver(long cPtr, boolean cMemoryOwn) {
102  swigCMemOwn = cMemoryOwn;
103  swigCPtr = cPtr;
104  }
105 
106  protected static long getCPtr(KnapsackSolver obj) {
107  return (obj == null) ? 0 : obj.swigCPtr;
108  }
109 
110  @SuppressWarnings("deprecation")
111  protected void finalize() {
112  delete();
113  }
114 
115  public synchronized void delete() {
116  if (swigCPtr != 0) {
117  if (swigCMemOwn) {
118  swigCMemOwn = false;
119  mainJNI.delete_KnapsackSolver(swigCPtr);
120  }
121  swigCPtr = 0;
122  }
123  }
124 
125  public KnapsackSolver(String solver_name) {
126  this(mainJNI.new_KnapsackSolver__SWIG_0(solver_name), true);
127  }
128 
129  public KnapsackSolver(KnapsackSolver.SolverType solver_type, String solver_name) {
130  this(mainJNI.new_KnapsackSolver__SWIG_1(solver_type.swigValue(), solver_name), true);
131  }
132 
136  public void init(long[] profits, long[][] weights, long[] capacities) {
137  mainJNI.KnapsackSolver_init(swigCPtr, this, profits, weights, capacities);
138  }
139 
143  public long solve() {
144  return mainJNI.KnapsackSolver_solve(swigCPtr, this);
145  }
146 
150  public boolean bestSolutionContains(int item_id) {
151  return mainJNI.KnapsackSolver_bestSolutionContains(swigCPtr, this, item_id);
152  }
153 
157  public boolean isSolutionOptimal() {
158  return mainJNI.KnapsackSolver_isSolutionOptimal(swigCPtr, this);
159  }
160 
161  public String getName() {
162  return mainJNI.KnapsackSolver_getName(swigCPtr, this);
163  }
164 
165  public boolean useReduction() {
166  return mainJNI.KnapsackSolver_useReduction(swigCPtr, this);
167  }
168 
169  public void setUseReduction(boolean use_reduction) {
170  mainJNI.KnapsackSolver_setUseReduction(swigCPtr, this, use_reduction);
171  }
172 
179  public void setTimeLimit(double time_limit_seconds) {
180  mainJNI.KnapsackSolver_setTimeLimit(swigCPtr, this, time_limit_seconds);
181  }
182 
189  public enum SolverType {
198  KNAPSACK_BRUTE_FORCE_SOLVER(mainJNI.KnapsackSolver_KNAPSACK_BRUTE_FORCE_SOLVER_get()),
206  KNAPSACK_64ITEMS_SOLVER(mainJNI.KnapsackSolver_KNAPSACK_64ITEMS_SOLVER_get()),
214  KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER(mainJNI.KnapsackSolver_KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER_get()),
221  KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER(mainJNI.KnapsackSolver_KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER_get()),
228  KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER(mainJNI.KnapsackSolver_KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER_get());
229 
230  public final int swigValue() {
231  return swigValue;
232  }
233 
234  public static SolverType swigToEnum(int swigValue) {
235  SolverType[] swigValues = SolverType.class.getEnumConstants();
236  if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
237  return swigValues[swigValue];
238  for (SolverType swigEnum : swigValues)
239  if (swigEnum.swigValue == swigValue)
240  return swigEnum;
241  throw new IllegalArgumentException("No enum " + SolverType.class + " with value " + swigValue);
242  }
243 
244  @SuppressWarnings("unused")
245  private SolverType() {
246  this.swigValue = SwigNext.next++;
247  }
248 
249  @SuppressWarnings("unused")
250  private SolverType(int swigValue) {
251  this.swigValue = swigValue;
252  SwigNext.next = swigValue+1;
253  }
254 
255  @SuppressWarnings("unused")
256  private SolverType(SolverType swigEnum) {
257  this.swigValue = swigEnum.swigValue;
258  SwigNext.next = this.swigValue+1;
259  }
260 
261  private final int swigValue;
262 
263  private static class SwigNext {
264  private static int next = 0;
265  }
266  }
267 
268 }
KnapsackSolver(KnapsackSolver.SolverType solver_type, String solver_name)
boolean isSolutionOptimal()
Returns true if the solution was proven optimal.
KNAPSACK_64ITEMS_SOLVER
Optimized method for single dimension small problems Limited to 64 items and one dimension,...
KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER
CBC Based Solver This solver can deal with both large number of items and several dimensions.
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.
KnapsackSolver(long cPtr, boolean cMemoryOwn)
Enum controlling which underlying algorithm is used.
This library solves knapsack problems.
long solve()
Solves the problem and returns the profit of the optimal solution.
KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER
Dynamic Programming approach for single dimension problems Limited to one dimension,...
boolean bestSolutionContains(int item_id)
Returns true if the item 'item_id' is packed in the optimal knapsack.