Sync g3 -> github
This commit is contained in:
@@ -25,9 +25,6 @@
|
||||
#include "ortools/algorithms/knapsack_solver.h"
|
||||
%}
|
||||
|
||||
typedef int64_t int64;
|
||||
typedef uint64_t uint64;
|
||||
|
||||
// See the comment in
|
||||
// ../../constraint_solver/csharp/constraint_solver.i about naming
|
||||
// the template instantiation of std::vector<> differently.
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
// Java wrapping of ../knapsack_solver.h. See that file.
|
||||
//
|
||||
// USAGE EXAMPLE (which is also used as unit test):
|
||||
// - java/com/google/ortools/samples/Knapsack.java
|
||||
// - java/com/google/ortools/algorithms/samples/Knapsack.java
|
||||
//
|
||||
// TODO(user): test all lines marked "untested".
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
// Python wrapping of ../knapsack_solver.h. See that file.
|
||||
//
|
||||
// USAGE EXAMPLES:
|
||||
// - examples/python/knapsack.py
|
||||
// - ortools/algorithms/samples/knapsack.py
|
||||
// - ./pywrapknapsack_solver_test.py
|
||||
|
||||
%include "stdint.i"
|
||||
|
||||
@@ -23,7 +23,8 @@ public class Knapsack
|
||||
{
|
||||
// [START solver]
|
||||
KnapsackSolver solver = new KnapsackSolver(
|
||||
KnapsackSolver.SolverType.KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER, "test");
|
||||
KnapsackSolver.SolverType.KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER,
|
||||
"KnapsackExample");
|
||||
// [END solver]
|
||||
|
||||
// [START data]
|
||||
@@ -44,14 +45,14 @@ public class Knapsack
|
||||
long[] capacities = { 850 };
|
||||
// [END data]
|
||||
|
||||
// [START print_solution]
|
||||
Console.WriteLine("Solving knapsack with " + values.Length +
|
||||
" items, and " + weights.GetLength(0) + " dimension");
|
||||
// [START solve]
|
||||
solver.Init(values, weights, capacities);
|
||||
long computedValue = solver.Solve();
|
||||
// [END solve]
|
||||
|
||||
// [START print_solution]
|
||||
Console.WriteLine("Optimal Value = " + computedValue);
|
||||
// [END print_solution]
|
||||
// [END print_solution]
|
||||
}
|
||||
}
|
||||
// [END program]
|
||||
|
||||
@@ -42,6 +42,8 @@ void RunKnapsackExample() {
|
||||
7, 29, 93, 44, 71, 3, 86, 66, 31, 65, 0, 79, 20, 65, 52, 13}};
|
||||
|
||||
std::vector<int64> capacities = {850};
|
||||
// [END data]
|
||||
|
||||
// [START solve]
|
||||
solver.Init(values, weights, capacities);
|
||||
int64 computed_value = solver.Solve();
|
||||
@@ -83,3 +85,4 @@ int main(int argc, char **argv) {
|
||||
operations_research::RunKnapsackExample();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
// [END program]
|
||||
|
||||
@@ -10,9 +10,8 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# [START program]
|
||||
"""A simple knapsack problem."""
|
||||
|
||||
# [START program]
|
||||
# [START import]
|
||||
from __future__ import print_function
|
||||
from ortools.algorithms import pywrapknapsack_solver
|
||||
@@ -23,8 +22,8 @@ def main():
|
||||
# Create the solver.
|
||||
# [START solver]
|
||||
solver = pywrapknapsack_solver.KnapsackSolver(
|
||||
pywrapknapsack_solver.KnapsackSolver.KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER,
|
||||
'KnapsackExample')
|
||||
pywrapknapsack_solver.KnapsackSolver.
|
||||
KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER, 'KnapsackExample')
|
||||
# [END solver]
|
||||
|
||||
# [START data]
|
||||
@@ -42,15 +41,15 @@ def main():
|
||||
capacities = [850]
|
||||
# [END data]
|
||||
|
||||
# [START solver]
|
||||
# [START solve]
|
||||
solver.Init(values, weights, capacities)
|
||||
computed_profit = solver.Solve()
|
||||
# [END solver]
|
||||
|
||||
# [START solve]
|
||||
print('optimal profit = ' + str(computed_profit))
|
||||
# [END solve]
|
||||
|
||||
# [START print_solution]
|
||||
print('optimal profit =', computed_profit)
|
||||
# [END print_solution]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -39,7 +39,7 @@ def create_data_model():
|
||||
[1420, 1374, 940, 1056, 879, 225, 1891, 1605, 1645, 679, 0, 1017, 1200],
|
||||
[2145, 357, 1453, 1280, 586, 887, 1114, 2300, 653, 1272, 1017, 0, 504],
|
||||
[1972, 579, 1260, 987, 371, 999, 701, 2099, 600, 1162, 1200, 504, 0],
|
||||
] # yapf: disable
|
||||
] # yapf: disable
|
||||
data['num_vehicles'] = 1
|
||||
data['depot'] = 0
|
||||
return data
|
||||
|
||||
@@ -29,7 +29,8 @@ public class SimpleLpProgram {
|
||||
public static void main(String[] args) throws Exception {
|
||||
// [START solver]
|
||||
// Create the linear solver with the GLOP backend.
|
||||
MPSolver solver = new MPSolver("SimpleLpProgram",
|
||||
MPSolver solver = new MPSolver(
|
||||
"SimpleLpProgram",
|
||||
MPSolver.OptimizationProblemType.GLOP_LINEAR_PROGRAMMING);
|
||||
// [END solver]
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ def main():
|
||||
x = solver.NumVar(0, 1, 'x')
|
||||
y = solver.NumVar(0, 2, 'y')
|
||||
|
||||
print('Number of variables = ', solver.NumVariables())
|
||||
print('Number of variables =', solver.NumVariables())
|
||||
# [END variables]
|
||||
|
||||
# [START constraints]
|
||||
@@ -39,7 +39,7 @@ def main():
|
||||
ct.SetCoefficient(x, 1)
|
||||
ct.SetCoefficient(y, 1)
|
||||
|
||||
print('Number of constraints = ', solver.NumConstraints())
|
||||
print('Number of constraints =', solver.NumConstraints())
|
||||
# [END constraints]
|
||||
|
||||
# [START objective]
|
||||
@@ -56,9 +56,9 @@ def main():
|
||||
|
||||
# [START print_solution]
|
||||
print('Solution:')
|
||||
print('Objective value = ', objective.Value())
|
||||
print('x = ', x.solution_value())
|
||||
print('y = ', y.solution_value())
|
||||
print('Objective value =', objective.Value())
|
||||
print('x =', x.solution_value())
|
||||
print('y =', y.solution_value())
|
||||
# [END print_solution]
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ def main():
|
||||
x = solver.IntVar(0.0, infinity, 'x')
|
||||
y = solver.IntVar(0.0, infinity, 'y')
|
||||
|
||||
print('Number of variables = ', solver.NumVariables())
|
||||
print('Number of variables =', solver.NumVariables())
|
||||
# [END variables]
|
||||
|
||||
# [START constraints]
|
||||
@@ -41,7 +41,7 @@ def main():
|
||||
# x <= 3.5.
|
||||
solver.Add(x <= 3.5)
|
||||
|
||||
print('Number of constraints = ', solver.NumConstraints())
|
||||
print('Number of constraints =', solver.NumConstraints())
|
||||
# [END constraints]
|
||||
|
||||
# [START objective]
|
||||
@@ -61,9 +61,9 @@ def main():
|
||||
|
||||
# [START print_solution]
|
||||
print('Solution:')
|
||||
print('Objective value = ', solver.Objective().Value())
|
||||
print('x = ', x.solution_value())
|
||||
print('y = ', y.solution_value())
|
||||
print('Objective value =', solver.Objective().Value())
|
||||
print('x =', x.solution_value())
|
||||
print('y =', y.solution_value())
|
||||
# [END print_solution]
|
||||
|
||||
# [START advanced]
|
||||
|
||||
Reference in New Issue
Block a user