Skip to content

Commit

Permalink
Move away from soon deprecated functions read_gpickle and write_gpick…
Browse files Browse the repository at this point in the history
…le (#99)

Co-authored-by: Philipp Ross <[email protected]>
  • Loading branch information
philross and Philipp Ross authored Dec 8, 2023
1 parent 0f6ab6c commit e5f826d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/modules/applications/optimization/PVC/PVC.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import itertools
from typing import TypedDict
import pickle

import networkx as nx
import numpy as np
Expand Down Expand Up @@ -137,7 +138,8 @@ def generate_problem(self, config: Config) -> nx.Graph:
seams = config['seams']

# Read in the original graph
graph = nx.read_gpickle(os.path.join(os.path.dirname(__file__), "data", "reference_graph.gpickle"))
with open(os.path.join(os.path.dirname(__file__), "data", "reference_graph.gpickle"), "rb") as file:
graph = pickle.load(file)

# Remove seams until the target number of seams is reached
# Get number of seam in graph
Expand Down Expand Up @@ -300,4 +302,5 @@ def evaluate(self, solution: list) -> (float, float):
return distance, end_time_measurement(start)

def save(self, path: str, iter_count: int) -> None:
nx.write_gpickle(self.application, f"{path}/graph_iter_{iter_count}.gpickle")
with open(f"{path}/graph_iter_{iter_count}.gpickle", "wb") as file:
pickle.dump(self.application, file, pickle.HIGHEST_PROTOCOL)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import networkx as nx
import pickle

# Read in the original graph
graph = nx.MultiDiGraph()
Expand Down Expand Up @@ -58,4 +59,5 @@
graph.add_edge((s_start, n_start), (s_end, n_end), c_start=c_start, t_start=t_start, c_end=c_end,
t_end=t_end, weight=duration)

nx.write_gpickle(graph, "reference_graph.gpickle")
with open("reference_graph.gpickle", "wb") as file:
pickle.dump(graph, file, pickle.HIGHEST_PROTOCOL)
7 changes: 5 additions & 2 deletions src/modules/applications/optimization/TSP/TSP.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

from typing import TypedDict
import pickle

import networkx as nx
import numpy as np
Expand Down Expand Up @@ -153,7 +154,8 @@ def generate_problem(self, config: Config) -> nx.Graph:
nodes = config['nodes']

# Read in the original graph
graph = nx.read_gpickle(os.path.join(os.path.dirname(__file__), "data", "reference_graph.gpickle"))
with open(os.path.join(os.path.dirname(__file__), "data", "reference_graph.gpickle"), "rb") as file:
graph = pickle.load(file)

# Remove seams until the target number of seams is reached
# Get number of seam in graph
Expand Down Expand Up @@ -293,4 +295,5 @@ def evaluate(self, solution: list) -> (float, float):
return distance_with_return, end_time_measurement(start)

def save(self, path: str, iter_count: int) -> None:
nx.write_gpickle(self.application, f"{path}/graph_iter_{iter_count}.gpickle")
with open(f"{path}/graph_iter_{iter_count}.gpickle", "wb") as file:
pickle.dump(self.application, file, pickle.HIGHEST_PROTOCOL)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import networkx as nx
import pickle
import tsplib95

# Source http://comopt.ifi.uni-heidelberg.de/software/TSPLIB95/tsp/
Expand All @@ -29,6 +30,7 @@
print("Loaded graph:")
print(nx.info(graph))

nx.write_gpickle(graph, "reference_graph.gpickle")
with open("reference_graph.gpickle", "wb") as file:
pickle.dump(graph, file, pickle.HIGHEST_PROTOCOL)

print("Saved graph as reference_graph.gpickle")

0 comments on commit e5f826d

Please sign in to comment.