pyepo.model.copt ================ .. py:module:: pyepo.model.copt .. autoapi-nested-parse:: Optimization Model based on Cardinal Optimizer(COPT) Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/pyepo/model/copt/coptmodel/index /autoapi/pyepo/model/copt/knapsack/index /autoapi/pyepo/model/copt/portfolio/index /autoapi/pyepo/model/copt/shortestpath/index /autoapi/pyepo/model/copt/tsp/index Classes ------- .. autoapisummary:: pyepo.model.copt.optCoptModel pyepo.model.copt.shortestPathModel pyepo.model.copt.knapsackModel pyepo.model.copt.knapsackModelRel pyepo.model.copt.tspGGModel pyepo.model.copt.tspGGModelRel pyepo.model.copt.tspDFJModel pyepo.model.copt.tspMTZModel pyepo.model.copt.tspMTZModelRel pyepo.model.copt.portfolioModel Package Contents ---------------- .. py:class:: optCoptModel Bases: :py:obj:`pyepo.model.opt.optModel` This is an abstract class for a Cardinal Optimizer optimization model .. attribute:: _model COPT model :type: COPT model .. py:method:: __repr__() .. py:method:: setObj(c) A method to set the objective function :param c: cost of objective function :type c: np.ndarray / list .. py:method:: solve() A method to solve the model :returns: optimal solution (list) and objective value (float) :rtype: tuple .. py:method:: copy() A method to copy the model :returns: new copied model :rtype: optModel .. py:method:: addConstr(coefs, rhs) A method to add a new constraint :param coefs: coefficients of new constraint :type coefs: np.ndarray / list :param rhs: right-hand side of new constraint :type rhs: float :returns: new model with the added constraint :rtype: optModel .. py:class:: shortestPathModel(grid) Bases: :py:obj:`pyepo.model.copt.coptmodel.optCoptModel` This class is an optimization model for the shortest path problem .. attribute:: _model COPT model :type: COPT model .. attribute:: grid size of grid network :type: tuple of int .. attribute:: arcs list of arcs :type: list .. py:attribute:: grid .. py:attribute:: arcs :value: [] .. py:method:: _getModel() A method to build COPT model .. py:class:: knapsackModel(weights, capacity) Bases: :py:obj:`pyepo.model.copt.coptmodel.optCoptModel` This class is an optimization model for the knapsack problem .. attribute:: _model COPT model :type: COPT model .. attribute:: weights weights of items :type: np.ndarray .. attribute:: capacity total capacity :type: np.ndarray .. attribute:: items list of item index :type: list .. py:attribute:: weights .. py:attribute:: capacity .. py:attribute:: items .. py:method:: _getModel() A method to build COPT model .. py:method:: relax() A method to get linear relaxation model .. py:class:: knapsackModelRel(weights, capacity) Bases: :py:obj:`knapsackModel` This class is relaxed optimization model for knapsack problem. .. py:method:: _getModel() A method to build COPT model .. py:method:: relax() A forbidden method to relax MIP model .. py:class:: tspGGModel(num_nodes) Bases: :py:obj:`tspABModel` This class is an optimization model for the traveling salesman problem based on Gavish-Graves (GG) formulation. .. attribute:: _model COPT model :type: COPT model .. attribute:: num_nodes Number of nodes :type: int .. attribute:: edges List of edge index :type: list .. py:method:: _getModel() A method to build COPT model :returns: optimization model and variables :rtype: tuple .. py:method:: setObj(c) A method to set the objective function :param c: cost vector :type c: list .. py:method:: solve() A method to solve model .. py:method:: addConstr(coefs, rhs) A method to add new constraint :param coefs: coefficients of new constraint :type coefs: ndarray :param rhs: right-hand side of new constraint :type rhs: float :returns: new model with the added constraint :rtype: optModel .. py:method:: relax() A method to get linear relaxation model .. py:class:: tspGGModelRel(num_nodes) Bases: :py:obj:`tspGGModel` This class is relaxation of tspGGModel. .. attribute:: _model COPT model :type: COPT model .. attribute:: num_nodes Number of nodes :type: int .. attribute:: edges List of edge index :type: list .. py:method:: _getModel() A method to build COPT model :returns: optimization model and variables :rtype: tuple .. py:method:: solve() A method to solve model :returns: optimal solution (list) and objective value (float) :rtype: tuple .. py:method:: relax() A forbidden method to relax MIP model .. py:method:: getTour(sol) A forbidden method to get a tour from solution .. py:class:: tspDFJModel(num_nodes) Bases: :py:obj:`tspABModel` This class is an optimization model for the traveling salesman problem based on Danzig-Fulkerson-Johnson (DFJ) formulation and constraint generation. .. attribute:: _model COPT model :type: COPT model .. attribute:: num_nodes Number of nodes :type: int .. attribute:: edges List of edge index :type: list .. py:class:: _SubtourCallback(x, n, edges) Bases: :py:obj:`coptpy.CallbackBase` A callback class for subtour elimination .. py:attribute:: _x .. py:attribute:: _n .. py:attribute:: _edges .. py:method:: callback() .. py:method:: _getModel() A method to build COPT model :returns: optimization model and variables :rtype: tuple .. py:method:: setObj(c) A method to set the objective function :param c: cost vector :type c: list .. py:method:: solve() A method to solve model .. py:method:: addConstr(coefs, rhs) A method to add new constraint :param coefs: coefficients of new constraint :type coefs: ndarray :param rhs: right-hand side of new constraint :type rhs: float :returns: new model with the added constraint :rtype: optModel .. py:class:: tspMTZModel(num_nodes) Bases: :py:obj:`tspABModel` This class is an optimization model for the traveling salesman problem based on Miller-Tucker-Zemlin (MTZ) formulation. .. attribute:: _model COPT model :type: COPT model .. attribute:: num_nodes Number of nodes :type: int .. attribute:: edges List of edge index :type: list .. py:method:: _getModel() A method to build COPT model :returns: optimization model and variables :rtype: tuple .. py:method:: setObj(c) A method to set the objective function :param c: cost vector :type c: list .. py:method:: solve() A method to solve model .. py:method:: addConstr(coefs, rhs) A method to add new constraint :param coefs: coefficients of new constraint :type coefs: ndarray :param rhs: right-hand side of new constraint :type rhs: float :returns: new model with the added constraint :rtype: optModel .. py:method:: relax() A method to get linear relaxation model .. py:class:: tspMTZModelRel(num_nodes) Bases: :py:obj:`tspMTZModel` This class is relaxation of tspMTZModel. .. attribute:: _model COPT model :type: COPT model .. attribute:: num_nodes Number of nodes :type: int .. attribute:: edges List of edge index :type: list .. py:method:: _getModel() A method to build COPT model :returns: optimization model and variables :rtype: tuple .. py:method:: solve() A method to solve model :returns: optimal solution (list) and objective value (float) :rtype: tuple .. py:method:: relax() A forbidden method to relax MIP model .. py:method:: getTour(sol) A forbidden method to get a tour from solution .. py:class:: portfolioModel(num_assets, covariance, gamma=2.25) Bases: :py:obj:`pyepo.model.copt.coptmodel.optCoptModel` This class is an optimization model for the portfolio problem .. attribute:: _model COPT model :type: COPT model .. attribute:: num_assets number of assets :type: int .. attribute:: covariance covariance matrix of the returns :type: numpy.ndarray .. attribute:: risk_level risk level :type: float .. py:attribute:: num_assets .. py:attribute:: covariance .. py:attribute:: risk_level .. py:method:: _getRiskLevel(gamma) A method to calculate the risk level :param gamma: risk level parameter :type gamma: float :returns: risk level :rtype: float .. py:method:: _getModel() A method to build COPT model :returns: optimization model and variables :rtype: tuple