pyepo.model.copt

Optimization Model based on Cardinal Optimizer(COPT)

Submodules

Classes

optCoptModel

This is an abstract class for a Cardinal Optimizer 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.

tspDFJModel

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

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.copt.optCoptModel

Bases: pyepo.model.opt.optModel

This is an abstract class for a Cardinal Optimizer optimization model

_model

COPT model

Type:

COPT model

__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.copt.shortestPathModel(grid)

Bases: pyepo.model.copt.coptmodel.optCoptModel

This class is an optimization model for the shortest path problem

_model

COPT model

Type:

COPT model

grid

size of grid network

Type:

tuple of int

arcs

list of arcs

Type:

list

grid
arcs = []
_getModel()

A method to build COPT model

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

Bases: pyepo.model.copt.coptmodel.optCoptModel

This class is an optimization model for the knapsack problem

_model

COPT model

Type:

COPT model

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

relax()

A method to get linear relaxation model

class pyepo.model.copt.knapsackModelRel(weights, capacity)

Bases: knapsackModel

This class is relaxed optimization model for knapsack problem.

_getModel()

A method to build COPT model

relax()

A forbidden method to relax MIP model

class pyepo.model.copt.tspGGModel(num_nodes)

Bases: tspABModel

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

_model

COPT model

Type:

COPT model

num_nodes

Number of nodes

Type:

int

edges

List of edge index

Type:

list

_getModel()

A method to build COPT 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.copt.tspGGModelRel(num_nodes)

Bases: tspGGModel

This class is relaxation of tspGGModel.

_model

COPT model

Type:

COPT model

num_nodes

Number of nodes

Type:

int

edges

List of edge index

Type:

list

_getModel()

A method to build COPT 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.copt.tspDFJModel(num_nodes)

Bases: tspABModel

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

_model

COPT model

Type:

COPT model

num_nodes

Number of nodes

Type:

int

edges

List of edge index

Type:

list

class _SubtourCallback(x, n, edges)

Bases: coptpy.CallbackBase

A callback class for subtour elimination

_x
_n
_edges
callback()
_getModel()

A method to build COPT 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

class pyepo.model.copt.tspMTZModel(num_nodes)

Bases: tspABModel

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

_model

COPT model

Type:

COPT model

num_nodes

Number of nodes

Type:

int

edges

List of edge index

Type:

list

_getModel()

A method to build COPT 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.copt.tspMTZModelRel(num_nodes)

Bases: tspMTZModel

This class is relaxation of tspMTZModel.

_model

COPT model

Type:

COPT model

num_nodes

Number of nodes

Type:

int

edges

List of edge index

Type:

list

_getModel()

A method to build COPT 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.copt.portfolioModel(num_assets, covariance, gamma=2.25)

Bases: pyepo.model.copt.coptmodel.optCoptModel

This class is an optimization model for the portfolio problem

_model

COPT model

Type:

COPT model

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

Returns:

optimization model and variables

Return type:

tuple