Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary update of available resources for drones #46

Merged
merged 1 commit into from
Oct 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions lapis/scheduler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from usim import Scope, instant, interval
from typing import Dict
from usim import Scope, interval

from lapis.drone import Drone

Expand Down Expand Up @@ -46,17 +47,22 @@ def unregister_drone(self, drone: Drone):
if len(cluster) == 0:
self.drone_cluster.remove(cluster)

def _add_drone(self, drone: Drone):
def _add_drone(self, drone: Drone, drone_resources: Dict = None):
minimum_distance_cluster = None
distance = float("Inf")
if len(self.drone_cluster) > 0:
for cluster in self.drone_cluster:
current_distance = 0
for key in {*cluster[0].pool_resources,
*drone.pool_resources}:
current_distance += abs(
cluster[0].theoretical_available_resources.get(key, 0)
- drone.theoretical_available_resources.get(key, 0))
if drone_resources:
current_distance += abs(
cluster[0].theoretical_available_resources.get(key, 0)
- drone_resources.get(key, 0))
else:
current_distance += abs(
cluster[0].theoretical_available_resources.get(key, 0)
- drone.theoretical_available_resources.get(key, 0))
if current_distance < distance:
minimum_distance_cluster = cluster
distance = current_distance
Expand All @@ -79,8 +85,14 @@ async def run(self):
best_match = self._schedule_job(job)
if best_match:
scope.do(best_match.start_job(job))
await instant
self.job_queue.remove(job)
self.unregister_drone(best_match)
left_resources = best_match.theoretical_available_resources
left_resources = {
key: value - job.resources.get(key, 0) for
key, value in left_resources.items()
}
self._add_drone(best_match, left_resources)
if not self._collecting and not self.job_queue:
break

Expand Down