omegalpes.general.optimisation package
Submodules
omegalpes.general.optimisation.core module
This module define the main Core object on which the energy units and actors will be based
- class omegalpes.general.optimisation.core.OptObject(name='U0', description='Optimization object', verbose=True)[source]
Bases:
objectDescription
OptObject class is used as an “abstract class”, i.e. it defines some general attributes and methods but doesn’t contain variable, constraint nor objective. In the OMEGAlpes package, all the subsystem models are represented by a unit. A model is then generated adding OptObject to it. Variable, objective and constraints declarations are usually done using the __init__ method of the OptObject class.
Attributes
name
description
_quantities_list : list of the quanitities of the OptObject (active or not)
_constraints_list : list of the constraints of the OptObject(active or not)
_technical_constraints_list : list of the constraints of the OptObject (active or not)
_objectives_list : list of the objectives of the OptObject (active or not)
Methods
__str__: defines the
__repr__: defines the unit with its name
get_constraints_list
get_constraints_name_list
get_external_constraints_list
get_external_constraints_name_list
get_objectives_list
get_objectives_name_list
get_quantities_list
get_quantities_name_list
deactivate_optobject_external_constraints
Note
The OptObject class shouldn’t be instantiated in a python script, except if you want to create your own model from the beginning. In this case, one should consider creating a new class NewModel(OptObject).
- deactivate_optobject_external_constraints(ext_cst_name_list=None)[source]
Enable to remove an external constraint linked with an OptObject
- Parameters:
ext_cst_name_list – list of external constraint that would be removed
- get_actor_constraints_list()[source]
Get the technical constraints associated with the unit as a dictionary shape [‘constraint_name’ , constraint]
- get_actor_constraints_name_list()[source]
Get the names of the external constraints associated with the unit
- get_constraints_list()[source]
Get the constraints associated with the unit as a dictionary shape [‘constraint_name’ , constraint]
- get_objectives_list()[source]
Get objectives associated with the unit as a dictionary shape [‘objective_name’ , objective]
- get_quantities_list()[source]
Get the quantities associated with the unit as a dictionary shape [‘quantity_name’ , quantity]
omegalpes.general.optimisation.elements module
This module includes the optimization elements (quantities, constraints and objectives) formulated in LP or MILP
Quantity : related to the decision variable or parameter
Constraint : related to the optimization problem constraints 4 categories of constraints :
Constraint: to define a constraint object
DefinitionConstraint: to calculate and define quantities or for physical
constraints - TechnicalConstraint: linked with technical constraints - ActorConstraint: constraint decided by the actors 2 types of constraints: - Constraints : basic constraint - DynamicConstraint: basic constraint depending on the time
Objective : related to the objective function
- class omegalpes.general.optimisation.elements.ActorConstraint(exp, name='ActCST0', description='', active=True, parent=None)[source]
Bases:
ConstraintDescription
Defining a category of constraint: ActorConstraint (see: DynamicConstraint, TechnicalConstraint) To model a constraint which is due to actor decisions. Must be different from Definition and Technical constraints. This kind of constraint is mainly a negotiable constraint.
example: to have a minimal level of energy consumption over a period. Constraint : min_energy
- class omegalpes.general.optimisation.elements.ActorDynamicConstraint(exp_t, t_range='for t in time.I', name='ActDynCST0', active=True, description='Actor and dynamic constraint', parent=None)[source]
Bases:
DynamicConstraint,ActorConstraintDescription
Defining a category of constraint: ActorDynamicConstraint (see: DynamicConstraint, ActorConstraint) Must be different from Definition and Technical constraints. This kind of constraint is mainly a negotiable constraint.
example: to operate an energy unit only on defined periods. Constraint: daily_dynamic_constraint
- class omegalpes.general.optimisation.elements.Constraint(exp, name='CST0', description='', active=True, parent=None)[source]
Bases:
objectDescription
Class that defines a constraint object
Attributes
name: name of the constraint
description: a description of the constraint
active: False = non-active constraint; True = active constraint
exp: (str) : expression of the constraint
parent: (unit) : this constraint belongs to this unit
Note
Make sure that all the modifications on Constraints are made before adding the unit to the Model (OptimisationModel.addUnit()).
- class omegalpes.general.optimisation.elements.DailyDynamicConstraint(exp_t, time, init_time: str = '00:00', final_time: str = '23:00', name='daily_dynamic_constraint', description='daily dynamic constraint', active=True, parent=None)[source]
Bases:
ActorDynamicConstraintDescription
Class that defines a daily dynamic constraint for a time range
Ex: Constraint applying between 7am and 10:30pm
ex_cst = DailyDynamicConstraint(exp_t, time, init_h=”7:00”, final_h=”10:30”, name=’ex_cst’)
Attributes
name (str) : name of the constraint
exp_t (str) : expression of the constraint
init_time (str) : starting time of the constraint in the format:
“HH:MM”, consistent with the dt value. - final_time (str) : ending time of the constraint in the format: “HH:MM”, consistent with the dt value. - description (str) : description of the constraint - active (bool) : defines if the constraint is active or not - parent (OptObject) : parent of the constraint
- class omegalpes.general.optimisation.elements.DefinitionConstraint(exp, name='DefCST0', description='Constraint for definitions', active=True, parent=None)[source]
Bases:
ConstraintDescription
Defining a category of constraint: DefinitionConstraint for imposed mathematical relation constraints, which may be physical. They are used to calculate and define quantities, or to reprensent physical phenomenon. Must be different from Technical and Actor constraints. This kind of constraint is by nature non-negotiable
Definition constraint: added to the model to calculate a quantity or define it considering an other.
example: the definition of e_tot: calc_e_tot (e_tot = LpSum(e))
Physical constraint: to model a constraint which is linked to the physics.
example: not implemented yet, see DefinitionDynamicConstraint
- class omegalpes.general.optimisation.elements.DefinitionDynamicConstraint(exp_t, t_range='for t in time.I', name='DefDynCST0', description='dynamic constraint for definition', active=True, parent=None)[source]
Bases:
DynamicConstraint,DefinitionConstraintDescription
Defining a category of constraint: DefinitionDynamicConstraint on the time. (see: DynamicConstraint, DefinitionConstraint) Must be different from Technical and Actor constraints. This kind of constraint is by nature non-negotiable
DefinitionDynamicConstraint: to calculate a quantity or define it considering an other quantity and depending on the time.
example: the definition of a capacity def_capacity (energy[t] <= capacity at each time step t)
- Physical constraint: to model physical constraints.
example: the power balance in an Energy node: power_balance
(LpSum(p_production_unit[t] for the set of production units connected to the energy node) = LpSum(p_consumption_unit[t] for the consumption units connected to the energy node at each time step t)
- class omegalpes.general.optimisation.elements.DynamicConstraint(exp_t, t_range='for t in time.I', name='DCST0', description='dynamic constraint', active=True, parent=None)[source]
Bases:
ConstraintDescription
Class that defines a constraint depending on the time. NB : Mandatory for PuLP
- class omegalpes.general.optimisation.elements.ExtDynConstraint(exp_t, t_range='for t in time.I', name='EDCST0', active=True, description='Non-physical and dynamic constraint', parent=None)[source]
Bases:
DynamicConstraint,ExternalConstraintDescription
DEPRECATED: please use ActorDynamicConstraint
Defining a constraint both external and dynamic (see: DynamicConstraint, ExternalConstraint)
- class omegalpes.general.optimisation.elements.ExternalConstraint(exp, name='ExCST0', description='', active=True, parent=None)[source]
Bases:
ConstraintDescription
DEPRECATED: please use ActorConstraint
- Defining a special type of constraint: the external constraint
This constraint does not translate a physical constraint
This constraint defines an external constraint, which could be relaxed
- class omegalpes.general.optimisation.elements.HourlyDynamicConstraint(exp_t, time, init_h: int = 0, final_h: int = 24, name='HDCST0', description='hourly dynamic constraint', active=True, parent=None)[source]
Bases:
ActorDynamicConstraintDescription
DEPRECATED: please use DailyDynamicConstraint
Class that defines an dynamic contraint for a time range
Ex: Constraint applying between 7am and 10pm
ex_cst = HourlyDynamicConstraint(exp_t, time, init_h=7, final_h=22, name=’ex_cst’)
Attributes
name (str) : name of the constraint
exp_t (str) : expression of the constraint
init_h (int) : hour of beginning of the constraint [0-23]
final_h (int) : hour of end of the constraint [1-24]
description (str) : description of the constraint
active (bool) : defines if the constraint is active or not
parent (OptObject) : parent of the constraint
- class omegalpes.general.optimisation.elements.Objective(exp, name='OBJ0', description='', active=True, weight=1, unit='s.u.', pareto=False, parent=None)[source]
Bases:
objectDescription
Class that defines an optimisation objective
Attributes
name (str) :
exp (str) :
description (str) :
active (bool) :
weight (float) : weighted factor of the objective
parent (unit)
unit (str) : unit of the cost expression
- pareto (str)if True, OMEGAlpes calculates a pareto front based on
this objective (two objectives needed)
Methods
_add_objectives_list()
_add_pareto_objectives_list()
Note
Make sure that all the modifications on Objectives are made before adding the unit to the OptimisationModel, otherwise, it won’t be taken into account
- class omegalpes.general.optimisation.elements.Quantity(name='var0', opt=True, unit='s.u', vlen=None, value=None, description='', vtype='Continuous', lb=None, ub=None, parent=None)[source]
Bases:
objectDescription
Class that defines what is a quantity. A quantity can wether be a decision variable or a parameter, depending on the opt parameter
Attributes
name (str) : the name of the quantity
description (str) : a description of the meaning of the quantity
vtype (PuLP) : the variable type, depending on PuLP
LpBinary (binary variable)
LpInteger (integer variable)
LpContinuous (continuous variable)
vlen (int) : size of the variable
unit (str) : unit of the quantity
opt (binary)
True: this is an optimization variable
False: this is a constant - a parameter
value (float, list, dict) : value (unused if opt=True)
ub, lb : upper and lower bounds
parent (OptObject) : the quantity belongs to this unit
Note
Make sure that all the modifications on Quantity are made before adding the unit to the Model
- class omegalpes.general.optimisation.elements.TechnicalConstraint(exp, name='TechCST0', description='Technical constraint', active=True, parent=None)[source]
Bases:
ConstraintDescription
Defining a category of constraint: TechnicalConstraint. To model a constraint which is linked to technical issues Must be different from Definition and Actor constraints. This kind of constraint is mainly a negotiable constraint.
example: not implemented yet, see TechnicalDynamicConstraints
- class omegalpes.general.optimisation.elements.TechnicalDynamicConstraint(exp_t, t_range='for t in time.I', name='TechCST0', active=True, description='Technical and dynamic constraint', parent=None)[source]
Bases:
DynamicConstraint,TechnicalConstraintDescription
Defining a category of constraint: TechnicalDynamicConstraint depending on the time. (see: DynamicConstraint, TechnicalConstraint) Must be different from Definition and Actor constraints. This kind of constraint is mainly a negotiable constraint.
example: an energy unit may not be able to stop in one time step, but several. The power decreases as a ramp shape: set_max_ramp_down
omegalpes.general.optimisation.model module
This module enables to fill the optimization model and formulate it in LP or MILP based on the package PuLP (LpProblem)
- class omegalpes.general.optimisation.model.OptimisationModel(time, name='optimisation_model')[source]
Bases:
LpProblemDescription
This class includes the optimization model formulated in LP or MILP based on the package PuLP (LpProblem)
- add_nodes(*nodes)[source]
Add nodes and all connected units to the model Check that the time is the same for the model and all the units
- Parameters:
nodes – EnergyNode
- add_nodes_and_actors(*nodes_or_actors)[source]
Add nodes, actors and all connected units to the model Check that the time is the same for the model and all the units
- Parameters:
nodes_or_actors – EnergyNode or Actor type
- solve_and_update(solver: LpSolver = None, find_infeasible_cst_set=False, pareto_step=0.1) None[source]
Solves the optimization model and updates all variables values.
- Parameters:
solver (LpSolver) – Optimization solver
pareto_step – if there are pareto objectives, you can change the step to calculate the pareto front
- omegalpes.general.optimisation.model.check_if_unit_could_have_parent(unit)[source]
Checks if the unit has an associated parent
- Parameters:
unit – unit which parents will be checked
- omegalpes.general.optimisation.model.compute_gurobi_IIS(gurobi_exe_path='C:\\gurobi810\\win64\\bin', opt_model=None, MPS_model=None)[source]
Identifies the constraints in a .ilp file
- Parameters:
gurobi_exe_path – Path to the gurobi solver “gurobi_cl.exe”
opt_model – OptimisationModel to whom compute IIS
MPS_model – name of the mps model