Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename line optimization input data columns #138

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/source/mods/line-optimization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ An example of the inputs with the respective requirements is shown below.
2 1 3 0.006 240
3 3 1 0.006 240
>>> line_data.head(4)
linename capacity fixCost operatingCost
linename capacity fix_cost operating_cost
0 new7_B 600 15 3
1 new15_B 600 15 2
2 new23_B 600 15 6
3 new31_B 600 15 6
>>> linepath_data.head(4)
linename edgeSource edgeTarget
linename edge_source edge_target
0 new7_B 1 2
1 new7_B 2 6
2 new7_B 6 8
Expand All @@ -183,7 +183,7 @@ An example of the inputs with the respective requirements is shown below.
the property length in the edge data.
Also, ``posx`` and ``posy`` in the ``node_data`` is not used for computation. But it can be used to visualize the
network as done below.
It is important that all data is consistant. For example, ``edgeSource``, ``edgeTarget``
It is important that all data is consistant. For example, ``edge_source``, ``edge_target``
in the ``linepath_data`` must correspond to a ``number`` in the node_data. The same holds
for ``source`` and ``target`` in ``edge_data`` and ``demand_data``.
In the code it is checked that all tables provide the relevant columns.
Expand Down
2 changes: 1 addition & 1 deletion src/gurobi_optimods/data/graphs/siouxfalls_linepaths.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
linename,edgeSource,edgeTarget
linename,edge_source,edge_target
new7_B,1,2
new7_B,2,6
new7_B,6,8
Expand Down
2 changes: 1 addition & 1 deletion src/gurobi_optimods/data/graphs/siouxfalls_lines.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
linename,capacity,fixCost,operatingCost
linename,capacity,fix_cost,operating_cost
new7_B,600,15,3
new15_B,600,15,2
new23_B,600,15,6
Expand Down
30 changes: 15 additions & 15 deletions src/gurobi_optimods/line_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def line_optimization(
It must include "source", "target", and "demand". The demand value must be non-negative.
line_data : DataFrame
DataFrame with general line information.
It must include "linename", "capacity", "fixCost", and "operatingCost".
It must include "linename", "capacity", "fix_cost", and "operating_cost".
linepath_data : DataFrame
DataFrame with information on the line routes/paths.
It must include "linename", "edgeSource", and "edgeTarget".
It must include "linename", "edge_source", and "edge_target".
frequency: List
List with possible frequencies: How often the line can be operated in the considered
time horizon.
Expand Down Expand Up @@ -85,20 +85,20 @@ def line_optimization(
if "capacity" not in line_data.columns:
logger.info("column capacity not present in line_data")
missing_data = True
if "fixCost" not in line_data.columns:
logger.info("column fixCost not present in line_data")
if "fix_cost" not in line_data.columns:
logger.info("column fix_cost not present in line_data")
missing_data = True
if "operatingCost" not in line_data.columns:
logger.info("column operatingCost not present in line_data")
if "operating_cost" not in line_data.columns:
logger.info("column operating_cost not present in line_data")
missing_data = True
if "linename" not in linepath_data.columns:
logger.info("column linename not present in linepath_data")
missing_data = True
if "edgeSource" not in linepath_data.columns:
logger.info("column edgeSource not present in linepath_data")
if "edge_source" not in linepath_data.columns:
logger.info("column edge_source not present in linepath_data")
missing_data = True
if "edgeTarget" not in linepath_data.columns:
logger.info("column edgeTarget not present in linepath_data")
if "edge_target" not in linepath_data.columns:
logger.info("column edge_target not present in linepath_data")
missing_data = True
if "source" not in demand_data.columns:
logger.info("column source not present in demand_data")
Expand Down Expand Up @@ -139,7 +139,7 @@ def line_optimization(
linepaths = (
linepath_data.set_index("linename")
.groupby(["linename"])
.apply(lambda x: [(k, v) for k, v in zip(x["edgeSource"], x["edgeTarget"])])
.apply(lambda x: [(k, v) for k, v in zip(x["edge_source"], x["edge_target"])])
)
demands = demand_data.set_index(["source", "target"]).to_dict()["demand"]

Expand Down Expand Up @@ -208,7 +208,7 @@ def all_shortest_paths(
for f in frequencies:
x[l, f] = model.addVar(
vtype=gp.GRB.BINARY,
obj=f * lines[l]["operatingCost"] + lines[l]["fixCost"],
obj=f * lines[l]["operating_cost"] + lines[l]["fix_cost"],
name=str(l) + str(f),
)

Expand Down Expand Up @@ -304,7 +304,7 @@ def allow_all_paths(
for f in frequencies:
x[l, f] = model.addVar(vtype=gp.GRB.BINARY, name=str(l) + str(f))
obj_cost += x[l, f] * (
f * lines[l]["operatingCost"] + lines[l]["fixCost"]
f * lines[l]["operating_cost"] + lines[l]["fix_cost"]
)

logger.info(
Expand Down Expand Up @@ -446,7 +446,7 @@ def plot_lineplan(
The frame must include "source", "target", and "time"
linepath_data : DataFrame
DataFrame with information on the line routes/paths.
It must include "linename", "edgeSource", and "edgeTarget".
It must include "linename", "edge_source", and "edge_target".
line_plan: List
A solution of the line optimization, i.e., a list with linenames and associated frequencies.

Expand All @@ -467,7 +467,7 @@ def plot_lineplan(
linepaths = (
linepath_data.set_index("linename")
.groupby(["linename"])
.apply(lambda x: [(k, v) for k, v in zip(x["edgeSource"], x["edgeTarget"])])
.apply(lambda x: [(k, v) for k, v in zip(x["edge_source"], x["edge_target"])])
)
G = nx.from_pandas_edgelist(edge_data.reset_index(), create_using=nx.Graph())
for number, row in node_data.set_index("number").iterrows():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_line_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@
"""

lines = """
linename,capacity,fixCost,operatingCost
linename,capacity,fix_cost,operating_cost
L1,20,9,4
L2,20,9,2
L3,20,9,3
"""

linepath = """
linename,edgeSource,edgeTarget
linename,edge_source,edge_target
L1,0,1
L1,1,3
L1,3,4
Expand Down