How to use the ortools.linear_solver.pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING function in ortools

To help you get started, we’ve selected a few ortools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / or-tools / examples / python / coloring_ip.py View on Github external
def main(sol='CBC'):

  # Create the solver.

  print('Solver: ', sol)

  if sol == 'GLPK':
    # using GLPK
    solver = pywraplp.Solver('CoinsGridGLPK',
                             pywraplp.Solver.GLPK_MIXED_INTEGER_PROGRAMMING)
  else:
    # Using CBC
    solver = pywraplp.Solver('CoinsGridCLP',
                             pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)

  #
  # data
  #

  # max number of colors
  # [we know that 4 suffices for normal maps]
  nc = 5

  # number of nodes
  n = 11
  # set of nodes
  V = list(range(n))

  num_edges = 20
github davehensley / fanduel-nba-optimizer / nba-optimizer.py View on Github external
def main(players, salaryCap):
    solver = pywraplp.Solver('CoinsGridCLP', pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)

    rangeC = range(len(players[0]))
    rangePG = range(len(players[1]))
    rangePF = range(len(players[2]))
    rangeSG = range(len(players[3]))
    rangeSF = range(len(players[4]))

    takeC = [solver.IntVar(0, 1, 'takeC[%i]' % j) for j in rangeC]
    takePG = [solver.IntVar(0, 1, 'takePG[%i]' % j) for j in rangePG]
    takePF = [solver.IntVar(0, 1, 'takePF[%i]' % j) for j in rangePF]
    takeSG = [solver.IntVar(0, 1, 'takeSG[%i]' % j) for j in rangeSG]
    takeSF = [solver.IntVar(0, 1, 'takeSF[%i]' % j) for j in rangeSF]

    teamsC = []
    teamsPG = []
    teamsPF = []
github google / or-tools / examples / python / steel_mill_slab_sat.py View on Github external
]

    ### Model problem.

    # Generate all valid slabs (columns)
    unsorted_valid_slabs = collect_valid_slabs_dp(capacities, colors, widths,
                                                  loss_array)
    # Sort slab by descending load/loss. Remove duplicates.
    valid_slabs = sorted(
        unsorted_valid_slabs, key=lambda c: 1000 * c[-1] + c[-2])
    all_valid_slabs = range(len(valid_slabs))

    # create model and decision variables.
    start_time = time.time()
    solver = pywraplp.Solver('Steel',
                             pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)
    selected = [
        solver.IntVar(0.0, 1.0, 'selected_%i' % i) for i in all_valid_slabs
    ]

    for order in all_orders:
        solver.Add(
            sum(selected[i] for i in all_valid_slabs
                if valid_slabs[i][order]) == 1)

    # Redundant constraint (sum of loads == sum of widths).
    solver.Add(
        sum(selected[i] * valid_slabs[i][-1]
            for i in all_valid_slabs) == sum(widths))

    # Objective.
    solver.Minimize(
github arogi / arogi-demos / interface / mclp_interface.py View on Github external
def RunCBCMCLPexampleCppStyleAPI(p, SD):
  if hasattr(pywraplp.Solver, 'CBC_MIXED_INTEGER_PROGRAMMING'):
    ###Announce('CBC', 'C++ style API')
    RunMCLPexampleCppStyleAPI(pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING, p, SD)
    return 0
github google / or-tools / ortools / linear_solver / samples / mip_var_array.py View on Github external
def main():
    # [START data]
    data = create_data_model()
    # [END data]

    # [START solver]
    # Create the mip solver with the CBC backend.
    solver = pywraplp.Solver('simple_mip_program',
                             pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)
    # [END solver]

    # [START variables]
    infinity = solver.infinity()
    x = {}
    for j in range(data['num_vars']):
        x[j] = solver.IntVar(0, infinity, 'x[%i]' % j)
    print('Number of variables =', solver.NumVariables())
    # [END variables]

    # [START constraints]
    for i in range(data['num_constraints']):
        constraint = solver.RowConstraint(0, data['bounds'][i], '')
        for j in range(data['num_vars']):
            constraint.SetCoefficient(x[j], data['constraint_coeffs'][i][j])
    print('Number of constraints =', solver.NumConstraints())
github arogi / arogi-demos / interface / pmedian_interface.py View on Github external
def RunAllPMedianExampleCppStyleAPI(p):
    if hasattr(pywraplp.Solver, 'CBC_MIXED_INTEGER_PROGRAMMING'):
        RunPMedianExampleCppStyleAPI(pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING, p)
github cohorte / cohorte-runtime / trunk / python / cohorte.python / cohorte / composer / node / distributor_csp.py View on Github external
# Normalize entries (components and isolates)
        components_names = sorted(component.name for component in components)
        nb_components = len(components_names)
        isolates_names = sorted(map_isolates.keys())

        # Compute boundaries
        max_isolates = max(len(components_names), len(isolates_names)) + 1


        # Prepare the incompatibility matrix
        incompat_matrix = self.__make_incompatibility_matrix(components_names)


        # Prepare the problem solver
        solver = ortools.Solver("Components distribution",
                                ortools.Solver.CBC_MIXED_INTEGER_PROGRAMMING)

        # Declare variables
        # ... component on isolate (Iso_i <=> Iso_i_j = 1)
        iso = {}
        for i, name in enumerate(components_names):
            for j in range(max_isolates):
                iso[i, j] = solver.IntVar(0, 1, "{0} on {1}".format(name, j))


        # ... assigned isolats (for the objective)
        assigned_isolates = [solver.IntVar(0, 1, "Isolate {0}".format(i))
                             for i in range(max_isolates)]

        # ... number of isolates for a component (must be 1)
        nb_component_isolate = [solver.Sum(iso[i, j]
                                           for j in range(max_isolates))
github google / or-tools / examples / python / diet1_mip.py View on Github external
def main(sol='CBC'):

  # Create the solver.

  print('Solver: ', sol)

  if sol == 'GLPK':
    # using GLPK
    solver = pywraplp.Solver('CoinsGridGLPK',
                             pywraplp.Solver.GLPK_MIXED_INTEGER_PROGRAMMING)
  else:
    # Using CBC
    solver = pywraplp.Solver('CoinsGridCLP',
                             pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)

  #
  # data
  #
  n = 4
  price = [50, 20, 30, 80]  # in cents
  limits = [500, 6, 10, 8]  # requirements for each nutrition type

  # nutritions for each product
  calories = [400, 200, 150, 500]
  chocolate = [3, 2, 0, 0]
  sugar = [2, 2, 4, 4]
  fat = [2, 4, 1, 5]

  #
  # declare variables
github google / or-tools / ortools / linear_solver / samples / simple_mip_program.py View on Github external
def main():
    # [START solver]
    # Create the mip solver with the CBC backend.
    solver = pywraplp.Solver('simple_mip_program',
                             pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)
    # [END solver]

    # [START variables]
    infinity = solver.infinity()
    # x and y are integer non-negative variables.
    x = solver.IntVar(0.0, infinity, 'x')
    y = solver.IntVar(0.0, infinity, 'y')

    print('Number of variables =', solver.NumVariables())
    # [END variables]

    # [START constraints]
    # x + 7 * y <= 17.5.
    solver.Add(x + 7 * y <= 17.5)

    # x <= 3.5.
github google / or-tools / examples / python / 3_jugs_mip.py View on Github external
def main(sol='CBC'):

  # Create the solver.

  print('Solver: ', sol)

  # using GLPK
  if sol == 'GLPK':
    solver = pywraplp.Solver('CoinsGridGLPK',
                             pywraplp.Solver.GLPK_MIXED_INTEGER_PROGRAMMING)
  else:
    # Using CBC
    solver = pywraplp.Solver('CoinsGridCBC',
                             pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)

  #
  # data
  #
  n = 15
  start = 0  # start node
  end = 14  # end node
  M = 999  # a large number

  nodes = [
      '8,0,0',  # start
      '5,0,3',
      '5,3,0',
      '2,3,3',
      '2,5,1',
      '7,0,1',