From cb1005e8d4063389e7d35aa47e72ac6559888683 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Mon, 6 Mar 2017 14:55:52 +0100 Subject: Add sanity check and reasonable defaults to model --- ilpscheduling/model.py | 25 +++++++++++++++++++++---- 1 file 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) -- cgit v1.2.3