webber-energy-group / HOwDI

https://howdi.readthedocs.io/en/develop/
GNU General Public License v3.0
0 stars 0 forks source link

Investigate cost and number of trucks #12

Closed bradenpecora closed 2 years ago

bradenpecora commented 2 years ago

Since there is no such thing as "half of a truck", we must make sure that the built truck capacity is a) an integer and b) consistent along distribution lines.

The model does not currently output the number of trucks on a distribution line. This requires adjusting create_graph.py.

This issue started as an investigation of residuals (dist_h $\approx 0$) in the output. The postprocessing script was written when I didn't quite understand capacity and dist_h, so the ultimate goal is to fix that and remove the residuals.

bradenpecora commented 2 years ago

The outputs of the model are the parameters and constraints in the objective function. So, even if a parameter or variable is initialized, it must be part of a set used in the objective function. As a result, some variables (namely dist_capacity for many arcs) do not make it to the objective function. The value is set to n/a in the outputs since there is still an associated row that does have some variables in the objective function. For example, since the arc/edge ({hubA_dist_truckLiquefied},{hubB_dist_truckLiquefied}) doesn't have a capital cost defined (rather than a capital cost of 0), the dist_capacity of this arc is not calculated (since capacity*capital is used for distribution in the objective)

Thus, to allow the model to output the number of trucks along a distribution line, I had to go through the model formation scripts and make sure that the relevant arcs all have dist_cost_capital, dist_cost_fixed, dist_cost_variable and dist_flow_limit so that a dist_capacity will be calculated. Before, these values were null (but not zero) and not used in the objective. For most cases, I made the values either 0 or 999999 so that they do not have an impact on the model solve. However, to get the capacity to be correct (and not one) for truck lines, I had to force the flow limit to the truck's flow limit. At this stage, this has no impact on the model objective.

However, now that we have the trucks leaving a local dist_truckLiquefied, it is apparent that the model is using more trucks that in creates. I will have to impose a constraint for this.

Also, these changes yield some code refactoring.

bradenpecora commented 2 years ago

Two constraints added:

    # the amount of trucks entering a hub's `truck{type}` node must be the same amount that is leaving
    def rule_truckConsistency(m, truck_dist_node):
        in_trucks = pe.summation(m.dist_capacity, index=m.g.in_edges(truck_dist_node))
        out_trucks = pe.summation(m.dist_capacity, index=m.g.out_edges(truck_dist_node))

        constraint = (in_trucks - out_trucks >= 0)
        return constraint
    m.const_truckConsistency = pe.Constraint(m.truck_set, rule=rule_truckConsistency)

Where truck_set is the set of all nodes that their names' constain 'dist_truck', i.e. austin_dist_truckLiquefied or texasCity_dist_truckCompressed.

    # flow in and out of a convertor must have consistent capacity; 
    # that is, conversion capacity into an arc must equal the capacity out of an arc
    # <= used because capacity was often dropped (in_capacity > out_capacity)in the approximate solution
    def rule_flowCapacityBetweenConverters(m, converterNode):
        in_capacity = pe.summation(m.dist_capacity, index=m.g.in_edges(converterNode))
        out_capacity = pe.summation(m.dist_capacity, index=m.g.out_edges(converterNode))
        constraint = (in_capacity -out_capacity <= 0)
        return constraint
    m.constr_flowCapacityBetweenConverters = pe.Constraint(m.converter_set, rule=rule_flowCapacityBetweenConverters)

Postprocessing shows that these constraints enforce consistency on distribution capacity.

bradenpecora commented 2 years ago

Issue resolved but there is some bad code. Code will be fixed in refactoring process

bradenpecora commented 2 years ago

I noticed this comment from Thomas:

consider adding a node at each hub to denote the trucking fleet size. Right now, this information is held in the arc between the compressor/liquefier and the trucking distribution node at that hub. Might be cleaner if we just had a truck_hub_node that stored the number of trucks that that hub invests in, and then we can just limit the flow of the outgoing edges to be constrained by the capacity at that node.

Regardless, it seems he came to the same conclusion I did. The current implementation is messy and needs work. I'm not happy with the way things are done here.

bradenpecora commented 2 years ago

Here is an example case:

image 125 trucks enter the node (waco_dist_truckLiquefied) and 126 trucks leave the node. Hydrogen has not been added, but capacity (a turck) has. Note: this scenario is without the constraints listed in this earlier comment

@joshdr83 this is also an example of trucks going from one hub and passing through another hub to reach a third hub. I don't think the model would chose to have an "intermediate" node like this that doesn't consume hydrogen, since data/base/arcs.csv generate by data/base/create_arcs.py lists most relevant arcs.

Scenario on look_into_dist_rework branch

bradenpecora commented 2 years ago

18