diff --git a/scripts/script_debug_optim.py b/scripts/script_debug_optim.py index 2f2dbb15..d5f4dcc1 100644 --- a/scripts/script_debug_optim.py +++ b/scripts/script_debug_optim.py @@ -69,9 +69,11 @@ } # Set special debug cases + optim_conf.update({'lp_solver': 'PULP_CBC_CMD'}) # set the name of the linear programming solver that will be used. Options are 'PULP_CBC_CMD', 'GLPK_CMD' and 'COIN_CMD'. + optim_conf.update({'lp_solver_path': 'empty'}) # set the path to the LP solver, COIN_CMD default is /usr/bin/cbc optim_conf.update({'treat_def_as_semi_cont': [True, True]}) optim_conf.update({'set_def_constant': [False, False]}) - optim_conf.update({'P_deferrable_nom': [[500.0, 1000.0, 1000.0, 500.0], 750.0]}) + optim_conf.update({'P_deferrable_nom': [[500.0, 100.0, 100.0, 500.0], 750.0]}) optim_conf.update({'set_use_battery': False}) optim_conf.update({'set_nocharge_from_grid': False}) diff --git a/src/emhass/optimization.py b/src/emhass/optimization.py index 6905808f..03fbf0f2 100644 --- a/src/emhass/optimization.py +++ b/src/emhass/optimization.py @@ -174,14 +174,14 @@ def perform_optimization(self, data_opt: pd.DataFrame, P_PV: np.array, P_load: n P_deferrable = [] P_def_bin1 = [] for k in range(self.optim_conf['num_def_loads']): + if type(self.optim_conf['P_deferrable_nom'][k]) == list: + upBound = np.max(self.optim_conf['P_deferrable_nom'][k]) + else: + upBound = self.optim_conf['P_deferrable_nom'][k] if self.optim_conf['treat_def_as_semi_cont'][k]: P_deferrable.append({(i):plp.LpVariable(cat='Continuous', name="P_deferrable{}_{}".format(k, i)) for i in set_I}) else: - if type(self.optim_conf['P_deferrable_nom'][k]) == list: - upBound = np.max(self.optim_conf['P_deferrable_nom'][k]) - else: - upBound = self.optim_conf['P_deferrable_nom'][k] P_deferrable.append({(i):plp.LpVariable(cat='Continuous', lowBound=0, upBound=upBound, name="P_deferrable{}_{}".format(k, i)) for i in set_I}) @@ -334,26 +334,26 @@ def create_matrix(input_list, n): return matrix matrix = create_matrix(power_sequence, n-sequence_length) y = plp.LpVariable.dicts(f"y{k}", (i for i in range(len(matrix))), cat='Binary') - constraints.update({f"SingleValueConstraint_{i}" : + constraints.update({f"single_value_constraint_{k}" : plp.LpConstraint( e = plp.lpSum(y[i] for i in range(len(matrix))) - 1, sense = plp.LpConstraintEQ, rhs = 0) }) - # constraints.update({f"pdef{k}_sumconstraint_{i}" : - # plp.LpConstraint( - # e = plp.lpSum(P_deferrable[k][i] for i in set_I) - np.sum(power_sequence), - # sense = plp.LpConstraintEQ, - # rhs = 0) - # }) - constraints.update({f"pdef{k}_positiveconstraint_{i}" : + constraints.update({f"pdef{k}_sumconstraint_{i}" : + plp.LpConstraint( + e = plp.lpSum(P_deferrable[k][i] for i in set_I) - np.sum(power_sequence), + sense = plp.LpConstraintEQ, + rhs = 0) + }) + constraints.update({f"pdef{k}_positive_constraint_{i}" : plp.LpConstraint( e = P_deferrable[k][i], sense = plp.LpConstraintGE, rhs = 0) for i in set_I}) for num, mat in enumerate(matrix): - constraints.update({f"pdef{k}_valueconstraint_{num}_{i}" : + constraints.update({f"pdef{k}_value_constraint_{num}_{i}" : plp.LpConstraint( e = P_deferrable[k][i] - mat[i]*y[num], sense = plp.LpConstraintEQ,