pyepo.model.grb

Optimization Model based on GurobiPy

Submodules

Package Contents

Classes

optGrbModel

This is an abstract class for Gurobi-based optimization model

shortestPathModel

This class is optimization model for shortest path problem

knapsackModel

This class is optimization model for knapsack problem

tspGGModel

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

tspDFJModel

This class is optimization model for traveling salesman problem based on Danzig–Fulkerson–Johnson (DFJ) formulation and

tspMTZModel

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

portfolioModel

This class is an optimization model for portfolio problem

class pyepo.model.grb.optGrbModel

Bases: pyepo.model.opt.optModel

This is an abstract class for Gurobi-based optimization model

_model

Gurobi model

Type:

GurobiPy model

property num_cost

number of cost to be predicted

__repr__()

Return repr(self).

setObj(c)

A method to set objective function

Parameters:

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

solve()

A method to solve model

Returns:

optimal solution (list) and objective value (float)

Return type:

tuple

copy()

A method to copy model

Returns:

new copied model

Return type:

optModel

addConstr(coefs, rhs)

A method to add new constraint

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

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

Returns:

new model with the added constraint

Return type:

optModel

class pyepo.model.grb.shortestPathModel(grid)

Bases: pyepo.model.grb.grbmodel.optGrbModel

This class is optimization model for shortest path problem

_model

Gurobi model

Type:

GurobiPy model

grid

Size of grid network

Type:

tuple of int

arcs

List of arcs

Type:

list

_getArcs()

A method to get list of arcs for grid network

Returns:

arcs

Return type:

list

_getModel()

A method to build Gurobi model

Returns:

optimization model and variables

Return type:

tuple

class pyepo.model.grb.knapsackModel(weights, capacity)

Bases: pyepo.model.grb.grbmodel.optGrbModel

This class is optimization model for knapsack problem

_model

Gurobi model

Type:

GurobiPy model

weights

Weights of items

Type:

np.ndarray / list

capacity

Total capacity

Type:

np.ndarray / listy

items

List of item index

Type:

list

_getModel()

A method to build Gurobi model

Returns:

optimization model and variables

Return type:

tuple

relax()

A method to get linear relaxation model

class pyepo.model.grb.tspGGModel(num_nodes)

Bases: tspABModel

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

_model

Gurobi model

Type:

GurobiPy model

num_nodes

Number of nodes

Type:

int

edges

List of edge index

Type:

list

_getModel()

A method to build Gurobi model

Returns:

optimization model and variables

Return type:

tuple

setObj(c)

A method to set 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) – coeffcients 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.grb.tspDFJModel(num_nodes)

Bases: tspABModel

This class is optimization model for traveling salesman problem based on Danzig–Fulkerson–Johnson (DFJ) formulation and constraint generation.

_model

Gurobi model

Type:

GurobiPy model

num_nodes

Number of nodes

Type:

int

edges

List of edge index

Type:

list

_getModel()

A method to build Gurobi model

Returns:

optimization model and variables

Return type:

tuple

static _subtourelim(model, where)

A static method to add lazy constraints for subtour elimination

setObj(c)

A method to set 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) – coeffcients of new constraint

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

Returns:

new model with the added constraint

Return type:

optModel

class pyepo.model.grb.tspMTZModel(num_nodes)

Bases: tspABModel

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

_model

Gurobi model

Type:

GurobiPy model

num_nodes

Number of nodes

Type:

int

edges

List of edge index

Type:

list

_getModel()

A method to build Gurobi model

Returns:

optimization model and variables

Return type:

tuple

setObj(c)

A method to set 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) – coeffcients 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.grb.portfolioModel(num_assets, covariance, gamma=2.25)

Bases: pyepo.model.grb.grbmodel.optGrbModel

This class is an optimization model for portfolio problem

_model

Gurobi model

Type:

GurobiPy model

num_assets

number of assets

Type:

int

covariance

covariance matrix of the returns

Type:

numpy.ndarray

risk_level

risk level

Type:

float

_getRiskLevel(gamma)

A method to calculate the risk level

Returns:

risk level

Return type:

float

_getModel()

A method to build Gurobi model

Returns:

optimization model and variables

Return type:

tuple