pyepo.model.ort

Optimization Model based on Google OR-Tools

Submodules

Classes

optOrtModel

This is an abstract class for an OR-Tools pywraplp optimization model

optOrtCpModel

This is an abstract class for an OR-Tools CP-SAT optimization model

shortestPathModel

This class is an optimization model for the shortest path problem

shortestPathCpModel

This class is an optimization model for the shortest path problem using CP-SAT

knapsackModel

This class is an optimization model for the knapsack problem

knapsackModelRel

This class is relaxed optimization model for knapsack problem.

knapsackCpModel

This class is an optimization model for the knapsack problem using CP-SAT

Package Contents

class pyepo.model.ort.optOrtModel(solver='scip')

Bases: pyepo.model.opt.optModel

This is an abstract class for an OR-Tools pywraplp optimization model

_model

OR-Tools linear solver

Type:

pywraplp.Solver

solver

solver backend (e.g. “scip”, “glop”, “cbc”)

Type:

str

solver = 'scip'
_extra_constrs = []
__repr__()
setObj(c)

A method to set the objective function

Parameters:

c (np.ndarray / list) – cost of objective function

solve()

A method to solve the model

Returns:

optimal solution (list) and objective value (float)

Return type:

tuple

copy()

A method to copy the model

Returns:

new copied model

Return type:

optModel

addConstr(coefs, rhs)

A method to add a new constraint

Parameters:
  • coefs (np.ndarray / list) – coefficients of new constraint

  • rhs (float) – right-hand side of new constraint

Returns:

new model with the added constraint

Return type:

optModel

class pyepo.model.ort.optOrtCpModel

Bases: pyepo.model.opt.optModel

This is an abstract class for an OR-Tools CP-SAT optimization model

_model

OR-Tools CP-SAT model

Type:

cp_model.CpModel

_OBJ_SCALE = 1000000
_extra_constrs = []
__repr__()
setObj(c)

A method to set the objective function

Parameters:

c (np.ndarray / list) – cost of objective function

solve()

A method to solve the model

Returns:

optimal solution (list) and objective value (float)

Return type:

tuple

copy()

A method to copy the model

Returns:

new copied model

Return type:

optModel

addConstr(coefs, rhs)

A method to add a new constraint

Parameters:
  • coefs (np.ndarray / list) – coefficients of new constraint

  • rhs (float) – right-hand side of new constraint

Returns:

new model with the added constraint

Return type:

optModel

relax()

CP-SAT does not support LP relaxation.

class pyepo.model.ort.shortestPathModel(grid, solver='glop')

Bases: pyepo.model.ort.ortmodel.optOrtModel

This class is an optimization model for the shortest path problem

_model

OR-Tools linear solver

Type:

pywraplp.Solver

solver

solver backend

Type:

str

grid

size of grid network

Type:

tuple of int

arcs

list of arcs

Type:

list

grid
arcs = []
_getModel()

A method to build OR-Tools pywraplp model

Returns:

optimization model and variables

Return type:

tuple

class pyepo.model.ort.shortestPathCpModel(grid)

Bases: pyepo.model.ort.ortcpmodel.optOrtCpModel

This class is an optimization model for the shortest path problem using CP-SAT

_model

OR-Tools CP-SAT model

Type:

cp_model.CpModel

grid

size of grid network

Type:

tuple of int

arcs

list of arcs

Type:

list

grid
arcs = []
_getModel()

A method to build OR-Tools CP-SAT model

Returns:

optimization model and variables

Return type:

tuple

class pyepo.model.ort.knapsackModel(weights, capacity, solver='scip')

Bases: pyepo.model.ort.ortmodel.optOrtModel

This class is an optimization model for the knapsack problem

_model

OR-Tools linear solver

Type:

pywraplp.Solver

solver

solver backend

Type:

str

weights

weights of items

Type:

np.ndarray

capacity

total capacity

Type:

np.ndarray

items

list of item index

Type:

list

weights
capacity
items
_getModel()

A method to build OR-Tools pywraplp model

Returns:

optimization model and variables

Return type:

tuple

relax()

A method to get linear relaxation model

class pyepo.model.ort.knapsackModelRel(weights, capacity, solver='scip')

Bases: knapsackModel

This class is relaxed optimization model for knapsack problem.

_getModel()

A method to build OR-Tools pywraplp model (relaxed)

Returns:

optimization model and variables

Return type:

tuple

relax()

A forbidden method to relax MIP model

class pyepo.model.ort.knapsackCpModel(weights, capacity)

Bases: pyepo.model.ort.ortcpmodel.optOrtCpModel

This class is an optimization model for the knapsack problem using CP-SAT

_model

OR-Tools CP-SAT model

Type:

cp_model.CpModel

weights

weights of items

Type:

np.ndarray

capacity

total capacity

Type:

np.ndarray

items

list of item index

Type:

list

weights
capacity
items
_getModel()

A method to build OR-Tools CP-SAT model

Returns:

optimization model and variables

Return type:

tuple