summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ilpscheduling/model.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/ilpscheduling/model.py b/ilpscheduling/model.py
index baa02d1..cf39c29 100644
--- a/ilpscheduling/model.py
+++ b/ilpscheduling/model.py
@@ -16,6 +16,11 @@ class WorkerSlotModel:
self.minTotalSlots = self._env.get ('minSlots', 0)
self.maxTotalSlots = self._env.get ('maxSlots', len (self.slotNames))
+ # sanity-checks
+ # min workers per slot must be smaller than total number of workers
+ for s in self.slotNames:
+ assert self.minWorker (s) <= len (self.workerNames), "Min workers per slot must be <= total workers"
+
@classmethod
def fromYaml (obj, fd):
"""
@@ -40,16 +45,28 @@ class WorkerSlotModel:
return self._worker[worker]['prio'].get (slot, None)
def maxSlots (self, worker):
- return self._worker[worker]['slots']['max']
+ """
+ Get max number of slots to assign to worker. Defaults to 1.
+ """
+ return self._worker[worker].get ('slots', {}).get ('max', 1)
def minSlots (self, worker):
- return self._worker[worker]['slots']['min']
+ """
+ Get min number of slots to assign to worker. Defaults to 1.
+ """
+ return self._worker[worker].get ('slots', {}).get ('min', 1)
def maxWorker (self, slot):
- return self._slots[slot]['max']
+ """
+ Get max number of worker for slot, defaults to #worker
+ """
+ return self._slots[slot].get ('max', len (self.workerNames))
def minWorker (self, slot):
- return self._slots[slot]['min']
+ """
+ Get min number of worker for slot. Defaults to 0.
+ """
+ return self._slots[slot].get ('min', 0)
def dump (self, fd):
yaml.dump ({'worker': self._worker, 'slots': self._slots, 'env': self._env}, fd)