diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2017-03-06 14:55:52 +0100 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2017-03-06 14:56:08 +0100 |
commit | cb1005e8d4063389e7d35aa47e72ac6559888683 (patch) | |
tree | aa7b74ab4ea23ba4cecd1618b094d6edee93d8a4 /ilpscheduling | |
parent | 17ce2f1f0ffd199c7f7d73bfaefd7846b792fecd (diff) | |
download | ilp-scheduling-cb1005e8d4063389e7d35aa47e72ac6559888683.tar.gz ilp-scheduling-cb1005e8d4063389e7d35aa47e72ac6559888683.tar.bz2 ilp-scheduling-cb1005e8d4063389e7d35aa47e72ac6559888683.zip |
Add sanity check and reasonable defaults to model
Diffstat (limited to 'ilpscheduling')
-rw-r--r-- | ilpscheduling/model.py | 25 |
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) |