parameters: (optimization_problem_type)
docstring: Example of simple linear program with the C++ style API.
docstring_summary: Example of simple linear program with the C++ style API.
docstring_tokens: Example of simple linear program with the C ++ style API .
function: def RunLinearExampleCppStyleAPI(optimization_problem_type):
      """Example of simple linear program with the C++ style API."""
      solver = pywraplp.Solver.CreateSolver(optimization_problem_type)
      if not solver:
          return
  
      Announce(optimization_problem_type, 'C++ style API')
  
      infinity = solver.infinity()
      # x1, x2 and x3 are continuous non-negative variables.
      x1 = solver.NumVar(0.0, infinity, 'x1')
      x2 = solver.NumVar(0.0, infinity, 'x2')
      x3 = solver.NumVar(0.0, infinity, 'x3')
  
      # Maximize 10 * x1 + 6 * x2 + 4 * x3.
      objective = solver.Objective()
      objective.SetCoefficient(x1, 10)
      objective.SetCoefficient(x2, 6)
      objective.SetCoefficient(x3, 4)
      objective.SetMaximization()
  
      # x1 + x2 + x3 <= 100.
      c0 = solver.Constraint(-infinity, 100.0, 'c0')
      c0.SetCoefficient(x1, 1)
      c0.SetCoefficient(x2, 1)
      c0.SetCoefficient(x3, 1)
  
      # 10 * x1 + 4 * x2 + 5 * x3 <= 600.
      c1 = solver.Constraint(-infinity, 600.0, 'c1')
      c1.SetCoefficient(x1, 10)
      c1.SetCoefficient(x2, 4)
      c1.SetCoefficient(x3, 5)
  
      # 2 * x1 + 2 * x2 + 6 * x3 <= 300.
      c2 = solver.Constraint(-infinity, 300.0, 'c2')
      c2.SetCoefficient(x1, 2)
      c2.SetCoefficient(x2, 2)
      c2.SetCoefficient(x3, 6)
  
      SolveAndPrint(solver, [x1, x2, x3], [c0, c1, c2])
function_tokens: def RunLinearExampleCppStyleAPI ( optimization_problem_type ) : solver = pywraplp . Solver . CreateSolver ( optimization_problem_type ) if not solver : return Announce ( optimization_problem_type , 'C++ style API' ) infinity = solver . infinity ( ) # x1, x2 and x3 are continuous non-negative variables. x1 = solver . NumVar ( 0.0 , infinity , 'x1' ) x2 = solver . NumVar ( 0.0 , infinity , 'x2' ) x3 = solver . NumVar ( 0.0 , infinity , 'x3' ) # Maximize 10 * x1 + 6 * x2 + 4 * x3. objective = solver . Objective ( ) objective . SetCoefficient ( x1 , 10 ) objective . SetCoefficient ( x2 , 6 ) objective . SetCoefficient ( x3 , 4 ) objective . SetMaximization ( ) # x1 + x2 + x3 <= 100. c0 = solver . Constraint ( - infinity , 100.0 , 'c0' ) c0 . SetCoefficient ( x1 , 1 ) c0 . SetCoefficient ( x2 , 1 ) c0 . SetCoefficient ( x3 , 1 ) # 10 * x1 + 4 * x2 + 5 * x3 <= 600. c1 = solver . Constraint ( - infinity , 600.0 , 'c1' ) c1 . SetCoefficient ( x1 , 10 ) c1 . SetCoefficient ( x2 , 4 ) c1 . SetCoefficient ( x3 , 5 ) # 2 * x1 + 2 * x2 + 6 * x3 <= 300. c2 = solver . Constraint ( - infinity , 300.0 , 'c2' ) c2 . SetCoefficient ( x1 , 2 ) c2 . SetCoefficient ( x2 , 2 ) c2 . SetCoefficient ( x3 , 6 ) SolveAndPrint ( solver , [ x1 , x2 , x3 ] , [ c0 , c1 , c2 ] )