Skip to content

Commit

Permalink
Changed maximum misses variable to minimum hits
Browse files Browse the repository at this point in the history
   - This is to reflect changes from kytos#62
  • Loading branch information
MarvinTorres committed Jul 29, 2020
1 parent f839b7f commit efa846d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,20 @@ def shortest_paths(self, source, destination, parameter=None):
return paths

def constrained_flexible_paths(self, source, destination,
maximum_misses=None, **metrics):
minimum_hits=None, **metrics):
"""Calculate the constrained shortest paths with flexibility."""
base = metrics.get("base", {})
flexible = metrics.get("flexible", {})
default_edge_list = list(self._filter_edges(
self.graph.edges(data=True), **base))
length = len(flexible)
if maximum_misses is None:
maximum_misses = length
maximum_misses = min(length, max(0, maximum_misses))
if minimum_hits is None:
minimum_hits = length
minimum_hits = min(length, max(0, minimum_hits))
results = []
paths = []
i = 0
while (paths == [] and i in range(0, maximum_misses+1)):
while (paths == [] and i in range(0, minimum_hits+1)):
for combo in combinations(flexible.items(), length-i):
additional = dict(combo)
paths = self._constrained_shortest_paths(
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ def shortest_constrained_path(self):
destination = data.get('destination')
base_metrics = data.get('base_metrics', {})
fle_metrics = data.get('flexible_metrics', {})
maximum_misses = data.get('maximum_misses')
minimum_hits = data.get('minimum_flexible_hits')
try:
paths = self.graph.constrained_flexible_paths(source, destination,
maximum_misses,
minimum_hits,
base=base_metrics,
flexible=fle_metrics)
return jsonify(paths)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def get_path(self, source, destination):
results = self.graph.shortest_paths(source, destination)
return results

def get_path_constrained(self, source, destination, maximum_misses=None,
def get_path_constrained(self, source, destination, minimum_hits=None,
**metrics):
"""Return the constrained shortest path"""
return self.graph.constrained_flexible_paths(source, destination,
maximum_misses,
minimum_hits,
**metrics)

@staticmethod
Expand Down

0 comments on commit efa846d

Please sign in to comment.