pyepo.model.omo

Optimization Model based on Pyomo

Submodules

Classes

optOmoModel

This is an abstract class for a Pyomo-based optimization model

shortestPathModel

This class is an optimization model for the shortest path problem

knapsackModel

This class is an optimization model for the knapsack problem

knapsackModelRel

This class is relaxed optimization model for knapsack problem.

tspGGModel

This class is an optimization model for the traveling salesman problem based on Gavish-Graves (GG) formulation.

tspGGModelRel

This class is relaxation of tspGGModel.

tspMTZModel

This class is an optimization model for the traveling salesman problem based on Miller-Tucker-Zemlin (MTZ) formulation.

tspMTZModelRel

This class is relaxation of tspMTZModel.

portfolioModel

This class is an optimization model for the portfolio problem

Package Contents

class pyepo.model.omo.optOmoModel(solver='glpk')

Bases: pyepo.model.opt.optModel

This is an abstract class for a Pyomo-based optimization model

_model

Pyomo model

Type:

Pyomo model

solver

optimization solver in the background

Type:

str

solver = 'glpk'
__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.omo.shortestPathModel(grid, solver='glpk')

Bases: pyepo.model.omo.omomodel.optOmoModel

This class is an optimization model for the shortest path problem

_model

Pyomo model

Type:

Pyomo model

solver

optimization solver in the background

Type:

str

grid

size of grid network

Type:

tuple of int

arcs

list of arcs

Type:

list

grid
arcs = []
_getModel()

A method to build Pyomo model

class pyepo.model.omo.knapsackModel(weights, capacity, solver='glpk')

Bases: pyepo.model.omo.omomodel.optOmoModel

This class is an optimization model for the knapsack problem

_model

Pyomo model

Type:

Pyomo model

solver

optimization solver in the background

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 Pyomo model

relax()

A method to get linear relaxation model

class pyepo.model.omo.knapsackModelRel(weights, capacity, solver='glpk')

Bases: knapsackModel

This class is relaxed optimization model for knapsack problem.

_getModel()

A method to build Pyomo model

relax()

A forbidden method to relax MIP model

class pyepo.model.omo.tspGGModel(num_nodes, solver='glpk')

Bases: tspABModel

This class is an optimization model for the traveling salesman problem based on Gavish-Graves (GG) formulation.

_model

Pyomo model

Type:

Pyomo model

solver

optimization solver in the background

Type:

str

num_nodes

Number of nodes

Type:

int

edges

List of edge index

Type:

list

_getModel()

A method to build Pyomo model

Returns:

optimization model and variables

Return type:

tuple

setObj(c)

A method to set the objective function

Parameters:

c (list) – cost vector

solve()

A method to solve model

addConstr(coefs, rhs)

A method to add new constraint

Parameters:
  • coefs (ndarray) – coefficients of new constraint

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

Returns:

new model with the added constraint

Return type:

optModel

relax()

A method to get linear relaxation model

class pyepo.model.omo.tspGGModelRel(num_nodes, solver='glpk')

Bases: tspGGModel

This class is relaxation of tspGGModel.

_model

Pyomo model

Type:

Pyomo model

solver

optimization solver in the background

Type:

str

num_nodes

Number of nodes

Type:

int

edges

List of edge index

Type:

list

_getModel()

A method to build Pyomo model

Returns:

optimization model and variables

Return type:

tuple

solve()

A method to solve model

Returns:

optimal solution (list) and objective value (float)

Return type:

tuple

relax()

A forbidden method to relax MIP model

getTour(sol)

A forbidden method to get a tour from solution

class pyepo.model.omo.tspMTZModel(num_nodes, solver='glpk')

Bases: tspABModel

This class is an optimization model for the traveling salesman problem based on Miller-Tucker-Zemlin (MTZ) formulation.

_model

Pyomo model

Type:

Pyomo model

solver

optimization solver in the background

Type:

str

num_nodes

Number of nodes

Type:

int

edges

List of edge index

Type:

list

_getModel()

A method to build Pyomo model

Returns:

optimization model and variables

Return type:

tuple

setObj(c)

A method to set the objective function

Parameters:

c (list) – cost vector

solve()

A method to solve model

addConstr(coefs, rhs)

A method to add new constraint

Parameters:
  • coefs (ndarray) – coefficients of new constraint

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

Returns:

new model with the added constraint

Return type:

optModel

relax()

A method to get linear relaxation model

class pyepo.model.omo.tspMTZModelRel(num_nodes, solver='glpk')

Bases: tspMTZModel

This class is relaxation of tspMTZModel.

_model

Pyomo model

Type:

Pyomo model

solver

optimization solver in the background

Type:

str

num_nodes

Number of nodes

Type:

int

edges

List of edge index

Type:

list

_getModel()

A method to build Pyomo model

Returns:

optimization model and variables

Return type:

tuple

solve()

A method to solve model

Returns:

optimal solution (list) and objective value (float)

Return type:

tuple

relax()

A forbidden method to relax MIP model

getTour(sol)

A forbidden method to get a tour from solution

class pyepo.model.omo.portfolioModel(num_assets, covariance, gamma=2.25, solver='glpk')

Bases: pyepo.model.omo.omomodel.optOmoModel

This class is an optimization model for the portfolio problem

_model

Pyomo model

Type:

Pyomo model

solver

optimization solver in the background

Type:

str

num_assets

number of assets

Type:

int

covariance

covariance matrix of the returns

Type:

numpy.ndarray

risk_level

risk level

Type:

float

num_assets
covariance
risk_level
_getRiskLevel(gamma)

A method to calculate the risk level

Parameters:

gamma (float) – risk level parameter

Returns:

risk level

Return type:

float

_getModel()

A method to build Pyomo model

Returns:

optimization model and variables

Return type:

tuple