Skip to content

Commit d2e313f

Browse files
committed
Reorganized project structure
1 parent ab797d1 commit d2e313f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+75
-72
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ test:
55
poetry run pytest tests/
66

77
test-coverage:
8-
poetry run pytest --cov=algorithms --cov-report xml tests
8+
poetry run pytest --cov=graph_algorithms --cov-report xml tests
99

1010
lint:
11-
poetry run flake8 algorithms
11+
poetry run flake8 graph_algorithms
1212

1313
selfcheck:
1414
poetry check
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- coding:utf-8 -*-
2+
3+
"""Dijkstra's algorithm."""

graph_algorithms/paths_in_graph/bellman_ford/bellman_ford.py renamed to graph_algorithms/algorithms/bellman_ford/bellman_ford.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""Implementation Bellman-Ford’s algorithm."""
22

3-
from graph_algorithms.paths_in_graph.relax import relax
3+
from graph_algorithms.algorithms.relax import relax
44

5-
from graph_algorithms.paths_in_graph.distance import make_distances
6-
from graph_algorithms.paths_in_graph.distance import set_distance
5+
from graph_algorithms.data_structure.distance import make_distances
6+
from graph_algorithms.data_structure.distance import set_distance
77

88
from graph_algorithms.exception.graph_exception import NotContainsVertexException
99
from graph_algorithms.exception.messages import not_contains_vertex_message

graph_algorithms/paths_in_graph/bfs/bfs.py renamed to graph_algorithms/algorithms/bfs/bfs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from graph_algorithms.exception.graph_exception import NotContainsVertexException
99
from graph_algorithms.exception.messages import not_contains_vertex_message
1010

11-
from graph_algorithms.paths_in_graph.bfs.queue import make_queue, enqueue, dequeue, is_empty
12-
from graph_algorithms.paths_in_graph.distance import get_distance, make_distances, not_visited, set_distance
11+
from graph_algorithms.algorithms.bfs.queue import make_queue, enqueue, dequeue, is_empty
12+
from graph_algorithms.data_structure.distance import get_distance, make_distances, not_visited, set_distance
1313

1414

1515
def bfs(graph, start_vertex):

graph_algorithms/dfs/connected_components.py renamed to graph_algorithms/algorithms/dfs/connected_components.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
"""Implementation of the algorithm for calculating the components of graph connectivity."""
44

5-
from graph_algorithms.dfs.explore import explore
5+
from graph_algorithms.algorithms.dfs.explore import explore
66

77

88
class _ConnectedComponents(object):

graph_algorithms/dfs/dfs_recursion.py renamed to graph_algorithms/algorithms/dfs/dfs_recursion.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
"""Implementation recursion depth-first search."""
44

5-
from graph_algorithms.dfs.explore import explore
5+
from graph_algorithms.algorithms.dfs.explore import explore
66

77

88
def dfs_recursion(graph, pre_visit, post_visit):

graph_algorithms/dfs/topological_sort.py renamed to graph_algorithms/algorithms/dfs/topological_sort.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"""Implementation topological sort using recursive algorithm DFS."""
44

55

6-
from graph_algorithms.dfs.dfs_recursion import dfs_recursion
7-
from graph_algorithms.dfs.contains_circle import contains_circle
6+
from graph_algorithms.algorithms.dfs.dfs_recursion import dfs_recursion
7+
from graph_algorithms.algorithms.dfs.contains_circle import contains_circle
88

99
from graph_algorithms.exception.graph_exception import GraphContainsCircleException
1010
from graph_algorithms.exception.messages import sorting_not_possible_message

graph_algorithms/paths_in_graph/dijkstra/dijkstra.py renamed to graph_algorithms/algorithms/dijkstra/dijkstra.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
"""Implementation Dijkstra’s algorithm."""
44

5-
from graph_algorithms.paths_in_graph.priority_queue.priority_queue import make_priority_queue
6-
from graph_algorithms.paths_in_graph.priority_queue.priority_queue import extract_min
7-
from graph_algorithms.paths_in_graph.priority_queue.priority_queue import set_priority
8-
from graph_algorithms.paths_in_graph.priority_queue.priority_queue import decrease_priority
9-
from graph_algorithms.paths_in_graph.priority_queue.priority_queue import is_empty
10-
11-
from graph_algorithms.paths_in_graph.distance import make_distances
12-
from graph_algorithms.paths_in_graph.distance import set_distance
13-
from graph_algorithms.paths_in_graph.relax import relax
14-
from graph_algorithms.paths_in_graph.relax import edge_weight
5+
from graph_algorithms.data_structure.priority_queue.priority_queue import make_priority_queue
6+
from graph_algorithms.data_structure.priority_queue.priority_queue import extract_min
7+
from graph_algorithms.data_structure.priority_queue.priority_queue import set_priority
8+
from graph_algorithms.data_structure.priority_queue.priority_queue import decrease_priority
9+
from graph_algorithms.data_structure.priority_queue.priority_queue import is_empty
10+
11+
from graph_algorithms.data_structure.distance import make_distances
12+
from graph_algorithms.data_structure.distance import set_distance
13+
from graph_algorithms.algorithms.relax import relax
14+
from graph_algorithms.algorithms.relax import edge_weight
1515

1616
from graph_algorithms.exception.graph_exception import NotContainsVertexException
1717
from graph_algorithms.exception.messages import not_contains_vertex_message

graph_algorithms/paths_in_graph/relax.py renamed to graph_algorithms/algorithms/relax.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
The function gets the edge (u, v) of the graph and and tries to improve the distance to v
44
"""
55

6-
from graph_algorithms.paths_in_graph.distance import get_distance
7-
from graph_algorithms.paths_in_graph.distance import set_distance
8-
from graph_algorithms.paths_in_graph.distance import number
6+
from graph_algorithms.data_structure.distance import get_distance
7+
from graph_algorithms.data_structure.distance import set_distance
8+
from graph_algorithms.data_structure.distance import number
99

1010

1111
def relax(first_vertex, second_vertex, distance):

graph_algorithms/topological_sort.py renamed to graph_algorithms/algorithms/topological_sort.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from collections import deque
66

7-
from graph_algorithms.dfs.contains_circle import contains_circle
7+
from graph_algorithms.algorithms.dfs.contains_circle import contains_circle
88
from graph_algorithms.exception.graph_exception import GraphContainsCircleException
99
from graph_algorithms.exception.messages import sorting_not_possible_message
1010

graph_algorithms/paths_in_graph/distance.py renamed to graph_algorithms/data_structure/distance.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
The collection stores items:
66
- key: vertex-identifier
7-
- value: disatance
7+
- value: distance
88
99
Doesn't check if a key is contained in a collection.
1010
"""
@@ -19,7 +19,7 @@ def make_distances(graph):
1919
graph: graph for construct collection
2020
2121
Returns:
22-
distance: collection (key:vertex-identifier, value:disatance)
22+
distance: collection (key:vertex-identifier, value:distance)
2323
"""
2424
return {vertex.identifier: None for vertex in graph}
2525

@@ -57,7 +57,7 @@ def number(distance):
5757
distance: distance for convert
5858
5959
Returns:
60-
disatance: if disatance == None then return sys.maxsize else distance
60+
distance: if distance == None then return sys.maxsize else distance
6161
"""
6262
if distance is None:
6363
return sys.maxsize

graph_algorithms/graph/graph.py renamed to graph_algorithms/data_structure/graph/graph.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# -*- coding:utf-8 -*-
22
"""Graph data structure implementation."""
33

4-
from graph_algorithms.graph.vertex import Vertex
4+
from graph_algorithms.data_structure.graph.vertex import Vertex
5+
from graph_algorithms.data_structure.graph.edge import Edge
56

67
from graph_algorithms.exception.graph_exception import GraphContainsVertexExemption
78
from graph_algorithms.exception.graph_exception import NotContainsVertexException
89
from graph_algorithms.exception.graph_exception import GraphIsEmptyException
910
from graph_algorithms.exception.messages import graph_is_empty_message
1011
from graph_algorithms.exception.messages import not_contains_vertex_message
1112
from graph_algorithms.exception.messages import graph_contains_vertex_message
12-
from graph_algorithms.graph.edge import Edge
1313

1414

1515
class Graph(object):

graph_algorithms/paths_in_graph/priority_queue/priority_queue.py renamed to graph_algorithms/data_structure/priority_queue/priority_queue.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Private data structure. Only for search algorithms.
66
"""
77

8-
from graph_algorithms.paths_in_graph.priority_queue.heapdict.heapdict import heapdict
8+
from graph_algorithms.data_structure.priority_queue.heapdict.heapdict import heapdict
99

1010
import sys
1111

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "graph algorithms"
3-
version = "0.5.1"
3+
version = "0.6.2"
44
description = "graph algorithms implementation"
55
authors = ["Denis <Dysprosium92@ya.ru>"]
66
license = "MIT"

setup.cfg

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ max-line-length = 100
66
doctests = True
77
enable-extensions = G
88
isort-show-traceback = True
9-
exclude = algorithms/paths_in_graph/priority_queue/heapdict
9+
exclude = graph_algorithms/data_structure/priority_queue/heapdict
1010

1111
ignore = I005, I004, I003, I001, WPS214, WPS420, D208, E501
1212

1313
per-file-ignores =
14-
algorithms/dfs/dfs_iterative.py: WPS440, WPS441, WPS507
15-
algorithms/paths_in_graph/distance.py: WPS502
16-
algorithms/paths_in_graph/bfs/queue.py: WPS507
17-
algorithms/exception/messages.py: DAR101
18-
algorithms/paths_in_graph/dijkstra/dijkstra.py: WPS347, WPS507, WPS201
19-
algorithms/paths_in_graph/priority_queue/priority_queue.py: WPS507
20-
algorithms/paths_in_graph/bellman_ford/bellman_ford.py: WPS518
14+
graph_algorithms/algorithms/dfs/dfs_iterative.py: WPS440, WPS441, WPS507
15+
graph_algorithms/data_structure/distance.py: WPS502
16+
graph_algorithms/algorithms/bfs/queue.py: WPS507
17+
graph_algorithms/exception/messages.py: DAR101
18+
graph_algorithms/algorithms/dijkstra/dijkstra.py: WPS347, WPS507, WPS201
19+
graph_algorithms/data_structure/priority_queue/priority_queue.py: WPS507
20+
graph_algorithms/algorithms/bellman_ford/bellman_ford.py: WPS518
2121

2222
[isort]
2323
# See https://github.com/timothycrosley/isort#multi-line-output-modes

tests/dfs/test_connected_components.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import pytest
66

7-
from algorithms.graph.graph import Graph
8-
from algorithms.dfs.connected_components import connected_components
7+
from graph_algorithms.data_structure.graph.graph import Graph
8+
from graph_algorithms.algorithms.dfs.connected_components import connected_components
99

1010

1111
def test_one_component():

tests/dfs/test_dfs.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
import pytest
66

7-
from algorithms.graph.graph import Graph
8-
from algorithms.dfs.dfs_recursion import dfs_recursion
9-
from algorithms.dfs.dfs_iterative import dfs_iterative
7+
from graph_algorithms.data_structure.graph.graph import Graph
8+
from graph_algorithms.algorithms.dfs.dfs_recursion import dfs_recursion
9+
from graph_algorithms.algorithms.dfs.dfs_iterative import dfs_iterative
1010

1111

1212
def test_all_vertex_visited_dfs_iterative1():

tests/dfs/test_topological_sort.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
import pytest
66

7-
from algorithms.dfs.topological_sort import topological_sort as dfs_topological_sort
8-
from algorithms.topological_sort import topological_sort
9-
from algorithms.graph.graph import Graph
7+
from graph_algorithms.algorithms.dfs.topological_sort import topological_sort as dfs_topological_sort
8+
from graph_algorithms.algorithms.topological_sort import topological_sort
9+
from graph_algorithms.data_structure.graph.graph import Graph
1010

1111

1212
def test_topological_sort1():

tests/paths_in_graph/test_bfs.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
import pytest
44

5-
from algorithms.paths_in_graph.bfs.bfs import bfs
6-
from algorithms.graph.graph import Graph
7-
from algorithms.graph.vertex import Vertex
5+
from graph_algorithms.algorithms.bfs.bfs import bfs
6+
from graph_algorithms.data_structure.graph.graph import Graph
7+
from graph_algorithms.data_structure.graph.graph import Vertex
88

9-
from algorithms.exception.graph_exception import NotContainsVertexException
10-
from algorithms.exception.messages import not_contains_vertex_message
9+
from graph_algorithms.exception.graph_exception import NotContainsVertexException
10+
from graph_algorithms.exception.messages import not_contains_vertex_message
1111

12-
from algorithms.exception.graph_exception import GraphIsEmptyException
13-
from algorithms.exception.messages import graph_is_empty_message
12+
from graph_algorithms.exception.graph_exception import GraphIsEmptyException
13+
from graph_algorithms.exception.messages import graph_is_empty_message
1414

1515

1616
def test_bfs_positive1():

tests/paths_in_graph/test_dijkstra.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
import pytest
44

5-
from algorithms.graph.graph import Graph
6-
from algorithms.graph.vertex import Vertex
5+
from graph_algorithms.data_structure.graph.graph import Graph
6+
from graph_algorithms.data_structure.graph.vertex import Vertex
77

8-
from algorithms.paths_in_graph.dijkstra.dijkstra import dijkstra
9-
from algorithms.paths_in_graph.bellman_ford.bellman_ford import bellman_ford
8+
from graph_algorithms.algorithms.dijkstra.dijkstra import dijkstra
9+
from graph_algorithms.algorithms.bellman_ford.bellman_ford import bellman_ford
1010

11-
from algorithms.paths_in_graph.distance import get_distance
11+
from graph_algorithms.data_structure.distance import get_distance
1212

13-
from algorithms.exception.graph_exception import NotContainsVertexException
14-
from algorithms.exception.messages import not_contains_vertex_message
13+
from graph_algorithms.exception.graph_exception import NotContainsVertexException
14+
from graph_algorithms.exception.messages import not_contains_vertex_message
1515

16-
from algorithms.exception.graph_exception import GraphIsEmptyException
17-
from algorithms.exception.messages import graph_is_empty_message
16+
from graph_algorithms.exception.graph_exception import GraphIsEmptyException
17+
from graph_algorithms.exception.messages import graph_is_empty_message
1818

1919

2020
@pytest.mark.parametrize("f", [dijkstra, bellman_ford])

tests/test_graph.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
import pytest
66

7-
from algorithms.graph.graph import Graph
7+
from graph_algorithms.data_structure.graph.graph import Graph
8+
from graph_algorithms.data_structure.graph.vertex import Vertex
89

9-
from algorithms.exception.graph_exception import GraphContainsVertexExemption
10-
from algorithms.exception.graph_exception import GraphIsEmptyException
11-
from algorithms.exception.graph_exception import NotContainsVertexException
10+
from graph_algorithms.exception.graph_exception import GraphContainsVertexExemption
11+
from graph_algorithms.exception.graph_exception import GraphIsEmptyException
12+
from graph_algorithms.exception.graph_exception import NotContainsVertexException
1213

13-
from algorithms.exception.messages import graph_contains_vertex_message
14-
from algorithms.exception.messages import graph_is_empty_message
15-
from algorithms.exception.messages import not_contains_vertex_message
16-
from algorithms.graph.vertex import Vertex
14+
from graph_algorithms.exception.messages import graph_contains_vertex_message
15+
from graph_algorithms.exception.messages import graph_is_empty_message
16+
from graph_algorithms.exception.messages import not_contains_vertex_message
1717

1818

1919
def test_make_graph():

0 commit comments

Comments
 (0)