Commit 8b68d801 authored by Unknown's avatar Unknown
Browse files

Piped ability to set the solver, added networks to the carbon tests

parent 23a3e3c4
Loading
Loading
Loading
Loading
Loading
+5 −31
Original line number Diff line number Diff line
@@ -152,27 +152,6 @@ class NetworkModel(EHubModel):

            setattr(self, name, variable)

# class NetworkModelWithTotalCarbon(NetworkModel):
#     """
#     A subclass that allows connections between hubs.
#     """

#     MAX_CARBON = 0

#     def __init__(self, *, excel=None, request=None, name=None, n=0, network=None, network_request=None, hub_id=None):
#         super().__init__(excel=excel, request=request, name=name, network=network, network_request=network_request, hub_id=hub_id)
#         if n is not None:
#             self.MAX_CARBON = n

#     @constraint()
#     def max_carbon_level(self):
#         """
#         A constraint for epsilon constraint method.
#         """
#         return self.total_carbon <= float(self.MAX_CARBON)



# NETWORK Link specific constraints:

@constraint()
@@ -237,13 +216,12 @@ def linear_power_flow_constraint(power, angle_from, angle_to, time, reactance):
        yield power[t] == 1/reactance * (angle_from[t] - angle_to[t])
    

def multiple_hubs(minimize_carbon=False, output_filename=None, input_files=None, network_excel=None, network_request=None, carbon_value=0, n=0):
def multiple_hubs(minimize_carbon=False, output_filename=None, input_files=None, network_excel=None, network_request=None, max_carbon=None, n=0, solver='glpk'):
    """
    Core function for solving of multiple PyEHub models.
    """
    if carbon_value is None:
        carbon_value = 0

    #TODO: Put the network request logic here
    # The default excel file for network, in the network directory
    if network_excel is None:
        network_excel_file = 'Input_files/network_input/network.xlsx'
@@ -264,11 +242,7 @@ def multiple_hubs(minimize_carbon=False, output_filename=None, input_files=None,
            file_name = f'{input_files}{i+1}.xlsx'
        excel_file = file_name

        if minimize_carbon:
            hub = NetworkModelWithTotalCarbon(excel=excel_file, name=f'hub{i+1}', n=carbon_value,
                                              network=network_excel_file, hub_id=i)
        else:
            hub = NetworkModel(excel=excel_file, name=f'hub{i+1}',
        hub = NetworkModel(excel=excel_file, name=f'hub{i+1}', max_carbon=max_carbon,
                                            network=network_excel_file, hub_id=i)
        hubs.append(hub)

@@ -427,7 +401,7 @@ def multiple_hubs(minimize_carbon=False, output_filename=None, input_files=None,
        objective += hub.objective

    # Now solve this model.
    status = pylp.solve(objective=objective, constraints=constraints, minimize=True)
    status = pylp.solve(objective=objective, constraints=constraints, minimize=True, solver=solver)

    #: Define the different sheets that we output
    sheets = [
+30.1 KiB

File added.

No diff preview for this file type.

+30.1 KiB

File added.

No diff preview for this file type.

+30.2 KiB

File added.

No diff preview for this file type.

+10 KiB

File added.

No diff preview for this file type.

Loading