Skip to content

Commit

Permalink
Format files with black
Browse files Browse the repository at this point in the history
  • Loading branch information
VaeterchenFrost committed Dec 18, 2024
1 parent 582e2aa commit 1ffa54f
Show file tree
Hide file tree
Showing 9 changed files with 663 additions and 553 deletions.
17 changes: 12 additions & 5 deletions tdvisu/construct_dpdb_visu.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@

from tdvisu.dijkstra import bidirectional_dijkstra as find_path
from tdvisu.reader import TwReader
from tdvisu.utilities import convert_to_adj, flatten, get_parser
from tdvisu.utilities import logging_cfg, read_yml_or_cfg
from tdvisu.utilities import (
convert_to_adj,
flatten,
get_parser,
logging_cfg,
read_yml_or_cfg,
)

LOGGER = logging.getLogger("construct_dpdb_visu.py")

Expand Down Expand Up @@ -486,7 +491,7 @@ def __init__(self, db, problem, intermed_nodes, tw_file=None):
super().__init__(db, problem, intermed_nodes)
self.tw_file = tw_file

def read_clauses(self):
def read_clauses(self): # pragma: no cover
raise NotImplementedError(self.__class__.__name__ + " can not read_clauses!")

@staticmethod
Expand Down Expand Up @@ -534,9 +539,11 @@ def construct(self) -> dict:
"num_vars": self.read_num_vars(),
}

general_gr = {"edges": self.read_twfile()} if self.tw_file else False
general_gr = (
{"edges": self.read_twfile()} if self.tw_file else False
) # pragma: no cover

timeline = self.read_timeline(edgearray)
timeline = self.read_timeline(edgearray) # pragma: no cover
return {

Check warning on line 547 in tdvisu/construct_dpdb_visu.py

View check run for this annotation

Codecov / codecov/patch

tdvisu/construct_dpdb_visu.py#L547

Added line #L547 was not covered by tests
"generalGraph": general_gr,
"tdTimeline": timeline,
Expand Down
21 changes: 11 additions & 10 deletions tdvisu/dijkstra.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from itertools import count


def bidirectional_dijkstra(edges, source, target, weight='weight'):
def bidirectional_dijkstra(edges, source, target, weight="weight"):
r"""Dijkstra's algorithm for shortest paths using bidirectional search.
Parameters
Expand Down Expand Up @@ -127,7 +127,7 @@ def bidirectional_dijkstra(edges, source, target, weight='weight'):
push = heappush
pop = heappop
# Init: [Forward, Backward]
dists = [{}, {}] # dictionary of final distances
dists = [{}, {}] # dictionary of final distances
paths = [{source: [source]}, {target: [target]}] # dictionary of paths
fringe = [[], []] # heap of (distance, node) for choosing node to expand
seen = [{source: 0}, {target: 0}] # dict of distances to seen nodes
Expand Down Expand Up @@ -164,8 +164,7 @@ def bidirectional_dijkstra(edges, source, target, weight='weight'):
vw_length = dists[direction][v] + weight(w, v, d)
if w in dists[direction]:
if vw_length < dists[direction][w]:
raise ValueError(
"Contradictory paths found: negative weights?")
raise ValueError("Contradictory paths found: negative weights?")
elif w not in seen[direction] or vw_length < seen[direction][w]:
# relaxing
seen[direction][w] = vw_length
Expand Down Expand Up @@ -229,12 +228,14 @@ def _weight_function(weight, multigraph: bool = False):
return lambda u, v, data: data.get(weight, 1)


if __name__ == "__main__": # pragma: no cover
if __name__ == "__main__": # pragma: no cover
# Show one example and print to console
EDGES = {2: {1: {}, 3: {}, 4: {}},
1: {2: {}},
3: {2: {}},
4: {2: {}, 5: {}},
5: {4: {}}}
EDGES = {
2: {1: {}, 3: {}, 4: {}},
1: {2: {}},
3: {2: {}},
4: {2: {}, 5: {}},
5: {4: {}},
}
RESULT = bidirectional_dijkstra(EDGES, 3, 5)
print(RESULT)
30 changes: 13 additions & 17 deletions tdvisu/logging.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
version: 1
---
formatters:
simple:
format: "%(asctime)s %(levelname)s %(message)s"
datefmt: "%H:%M:%S"
full:
format: "%(asctime)s,%(msecs)d %(levelname)s[%(filename)s:%(lineno)d] %(message)s"
datefmt: "%Y-%m-%d %H:%M:%S"
datefmt: '%Y-%m-%d %H:%M:%S'
format: '%(asctime)s,%(msecs)d %(levelname)s[%(filename)s:%(lineno)d] %(message)s'
simple:
datefmt: '%H:%M:%S'
format: '%(asctime)s %(levelname)s %(message)s'
handlers:
console:
class: logging.StreamHandler
level: WARNING
formatter: full
level: WARNING
stream: ext://sys.stdout
loggers:
visualization.py:
level: NOTSET

svgjoin.py:
construct_dpdb_visu.py:
level: NOTSET

reader.py:
level: NOTSET

construct_dpdb_visu.py:
svgjoin.py:
level: NOTSET

utilities.py:
level: NOTSET

visualization.py:
level: NOTSET
root:
level: WARNING
handlers: [console]
level: WARNING
version: 1
16 changes: 10 additions & 6 deletions tdvisu/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ def main()

from tdvisu.utilities import add_edge_to

logger = logging.getLogger('reader.py')
logger = logging.getLogger("reader.py")


class Reader():
class Reader:
"""Base class for string-readers."""

@classmethod
def from_filename(cls, fname) -> Reader:
with open(fname, "r") as file:
Expand Down Expand Up @@ -150,7 +151,7 @@ def store_problem_vars(self):

def body(self, lines) -> None:
"""Store the content from the given lines in the edges and adjacency_dict."""
if self.format not in ('col', 'tw'):
if self.format not in ("col", "tw"):
logger.error("Not a tw file!")
sys.exit(1)

Expand All @@ -163,13 +164,16 @@ def body(self, lines) -> None:
logger.warning(
"Expected exactly 2 vertices at line %d, but %d found",
lineno,
len(line))
len(line),
)
vertex1 = int(line[0])
vertex2 = int(line[1])

add_edge_to(self.edges, self.adjacency_dict, vertex1, vertex2)

if len(self.edges) != self.num_edges:
logger.warning(
"Number of edges mismatch preamble (%d vs %d)", len(
self.edges), self.num_edges)
"Number of edges mismatch preamble (%d vs %d)",
len(self.edges),
self.num_edges,
)
Loading

0 comments on commit 1ffa54f

Please sign in to comment.