Skip to content

Commit

Permalink
Move away from soon deprecated functions read_gpickle and write_gpickle
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Ross authored and Philipp Ross committed Nov 30, 2023
1 parent f2a9050 commit 7c6ace1
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 @@ -16,6 +16,7 @@
from typing import TypedDict

import networkx as nx
import pickle

Check failure on line 19 in src/modules/applications/optimization/PVC/PVC.py

View workflow job for this annotation

GitHub Actions / Pylint

src/modules/applications/optimization/PVC/PVC.py#L19

Standard import "import pickle" should be placed before "import networkx as nx" (wrong-import-order, C0411)
import numpy as np

from modules.applications.Application import *
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 @@ -15,6 +15,7 @@
from typing import TypedDict

import networkx as nx
import pickle

Check failure on line 18 in src/modules/applications/optimization/TSP/TSP.py

View workflow job for this annotation

GitHub Actions / Pylint

src/modules/applications/optimization/TSP/TSP.py#L18

Standard import "import pickle" should be placed before "import networkx as nx" (wrong-import-order, C0411)
import numpy as np

from modules.applications.Application import *
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 7c6ace1

Please sign in to comment.