Skip to content

Commit

Permalink
Sync g3 -> github
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed May 14, 2019
1 parent 6cc1df0 commit d7a3354
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 31 deletions.
3 changes: 0 additions & 3 deletions ortools/algorithms/csharp/knapsack_solver.i
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ortools/algorithms/java/knapsack_solver.i
Original file line number Diff line number Diff line change
Expand Up @@ -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".

Expand Down
2 changes: 1 addition & 1 deletion ortools/algorithms/python/knapsack_solver.i
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 6 additions & 5 deletions ortools/algorithms/samples/Knapsack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ static void Main()
{
// [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]
Expand All @@ -44,14 +45,14 @@ static void Main()
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]
3 changes: 3 additions & 0 deletions ortools/algorithms/samples/knapsack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -83,3 +85,4 @@ int main(int argc, char **argv) {
operations_research::RunKnapsackExample();
return EXIT_SUCCESS;
}
// [END program]
17 changes: 8 additions & 9 deletions ortools/algorithms/samples/knapsack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion ortools/constraint_solver/samples/tsp_cities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion ortools/linear_solver/samples/SimpleLpProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
10 changes: 5 additions & 5 deletions ortools/linear_solver/samples/simple_lp_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]


Expand Down
10 changes: 5 additions & 5 deletions ortools/linear_solver/samples/simple_mip_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down

0 comments on commit d7a3354

Please sign in to comment.