1# Copyright 2011 Hakan Kjellerstrand hakank@gmail.com
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""
15
16  Volsay problem in Google or-tools.
17
18  From the OPL model volsay.mod
19
20  This model was created by Hakan Kjellerstrand (hakank@gmail.com)
21  Also see my other Google CP Solver models:
22  http://www.hakank.org/google_or_tools/
23"""
24from ortools.linear_solver import pywraplp
25
26
27def main(unused_argv):
28
29  # Create the solver.
30
31  # using GLPK
32  #solver = pywraplp.Solver('CoinsGridGLPK',
33  #                         pywraplp.Solver.GLPK_LINEAR_PROGRAMMING)
34
35  # Using CLP
36  solver = pywraplp.Solver('CoinsGridCLP',
37                           pywraplp.Solver.CLP_LINEAR_PROGRAMMING)
38
39  # data
40
41  # declare variables
42  Gas = solver.NumVar(0, 100000, 'Gas')
43  Chloride = solver.NumVar(0, 100000, 'Cloride')
44
45  #
46  # constraints
47  #
48  solver.Add(Gas + Chloride <= 50)
49  solver.Add(3 * Gas + 4 * Chloride <= 180)
50
51  # objective
52  objective = solver.Maximize(40 * Gas + 50 * Chloride)
53
54  print('NumConstraints:', solver.NumConstraints())
55
56  #
57  # solution and search
58  #
59  solver.Solve()
60
61  print()
62  print('objective = ', solver.Objective().Value())
63  print('Gas = ', Gas.SolutionValue(), 'ReducedCost =', Gas.ReducedCost())
64  print('Chloride:', Chloride.SolutionValue(), 'ReducedCost =',
65        Chloride.ReducedCost())
66
67
68if __name__ == '__main__':
69  main('Volsay')
70