Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
KnapsackSolver.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.algorithms;
10
92public class KnapsackSolver {
93 private transient long swigCPtr;
94 protected transient boolean swigCMemOwn;
95
96 protected KnapsackSolver(long cPtr, boolean cMemoryOwn) {
97 swigCMemOwn = cMemoryOwn;
98 swigCPtr = cPtr;
99 }
100
101 protected static long getCPtr(KnapsackSolver obj) {
102 return (obj == null) ? 0 : obj.swigCPtr;
103 }
104
105 protected static long swigRelease(KnapsackSolver obj) {
106 long ptr = 0;
107 if (obj != null) {
108 if (!obj.swigCMemOwn)
109 throw new RuntimeException("Cannot release ownership as memory is not owned");
110 ptr = obj.swigCPtr;
111 obj.swigCMemOwn = false;
112 obj.delete();
113 }
114 return ptr;
115 }
116
117 @SuppressWarnings({"deprecation", "removal"})
118 protected void finalize() {
119 delete();
120 }
121
122 public synchronized void delete() {
123 if (swigCPtr != 0) {
124 if (swigCMemOwn) {
125 swigCMemOwn = false;
126 mainJNI.delete_KnapsackSolver(swigCPtr);
127 }
128 swigCPtr = 0;
129 }
130 }
131
132 public KnapsackSolver(String solver_name) {
133 this(mainJNI.new_KnapsackSolver__SWIG_0(solver_name), true);
134 }
135
136 public KnapsackSolver(KnapsackSolver.SolverType solver_type, String solver_name) {
137 this(mainJNI.new_KnapsackSolver__SWIG_1(solver_type.swigValue(), solver_name), true);
138 }
139
143 public void init(long[] profits, long[][] weights, long[] capacities) {
144 mainJNI.KnapsackSolver_init(swigCPtr, this, profits, weights, capacities);
145 }
146
150 public long solve() {
151 return mainJNI.KnapsackSolver_solve(swigCPtr, this);
152 }
153
157 public boolean bestSolutionContains(int item_id) {
158 return mainJNI.KnapsackSolver_bestSolutionContains(swigCPtr, this, item_id);
159 }
160
164 public boolean isSolutionOptimal() {
165 return mainJNI.KnapsackSolver_isSolutionOptimal(swigCPtr, this);
166 }
167
168 public String getName() {
169 return mainJNI.KnapsackSolver_getName(swigCPtr, this);
170 }
171
172 public boolean useReduction() {
173 return mainJNI.KnapsackSolver_useReduction(swigCPtr, this);
174 }
175
176 public void setUseReduction(boolean use_reduction) {
177 mainJNI.KnapsackSolver_setUseReduction(swigCPtr, this, use_reduction);
178 }
179
185 public void setTimeLimit(double time_limit_seconds) {
186 mainJNI.KnapsackSolver_setTimeLimit(swigCPtr, this, time_limit_seconds);
187 }
188
194 public enum SolverType {
203 KNAPSACK_BRUTE_FORCE_SOLVER(mainJNI.KnapsackSolver_KNAPSACK_BRUTE_FORCE_SOLVER_get()),
211 KNAPSACK_64ITEMS_SOLVER(mainJNI.KnapsackSolver_KNAPSACK_64ITEMS_SOLVER_get()),
219 KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER(mainJNI.KnapsackSolver_KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER_get()),
226 KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER(mainJNI.KnapsackSolver_KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER_get()),
233 KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER(mainJNI.KnapsackSolver_KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER_get()),
240 KNAPSACK_MULTIDIMENSION_SCIP_MIP_SOLVER(mainJNI.KnapsackSolver_KNAPSACK_MULTIDIMENSION_SCIP_MIP_SOLVER_get()),
249 KNAPSACK_DIVIDE_AND_CONQUER_SOLVER(mainJNI.KnapsackSolver_KNAPSACK_DIVIDE_AND_CONQUER_SOLVER_get()),
256 KNAPSACK_MULTIDIMENSION_CP_SAT_SOLVER(mainJNI.KnapsackSolver_KNAPSACK_MULTIDIMENSION_CP_SAT_SOLVER_get());
257
258 public final int swigValue() {
259 return swigValue;
260 }
261
262 public static SolverType swigToEnum(int swigValue) {
263 SolverType[] swigValues = SolverType.class.getEnumConstants();
264 if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
265 return swigValues[swigValue];
266 for (SolverType swigEnum : swigValues)
267 if (swigEnum.swigValue == swigValue)
268 return swigEnum;
269 throw new IllegalArgumentException("No enum " + SolverType.class + " with value " + swigValue);
270 }
271
272 @SuppressWarnings("unused")
273 private SolverType() {
274 this.swigValue = SwigNext.next++;
275 }
276
277 @SuppressWarnings("unused")
278 private SolverType(int swigValue) {
279 this.swigValue = swigValue;
280 SwigNext.next = swigValue+1;
281 }
282
283 @SuppressWarnings("unused")
284 private SolverType(SolverType swigEnum) {
285 this.swigValue = swigEnum.swigValue;
286 SwigNext.next = this.swigValue+1;
287 }
288
289 private final int swigValue;
290
291 private static class SwigNext {
292 private static int next = 0;
293 }
294 }
295
296}
static long swigRelease(KnapsackSolver obj)
static long getCPtr(KnapsackSolver obj)
KnapsackSolver(long cPtr, boolean cMemoryOwn)
void init(long[] profits, long[][] weights, long[] capacities)
void setTimeLimit(double time_limit_seconds)
KnapsackSolver(KnapsackSolver.SolverType solver_type, String solver_name)