Esempio n. 1
0
    def __init__(
        self,
        name: str,
        duration: int,
        work_amount: Optional[int] = 0,
        priority: Optional[int] = 1,
        optional: Optional[bool] = False,
    ) -> None:
        super().__init__(name, optional)
        if not is_strict_positive_integer(duration):
            raise TypeError("duration must be a strict positive integer")
        self.duration_defined_value = duration

        if not is_positive_integer(work_amount):
            raise TypeError("work_amount me be a positive integer")
        self.work_amount = work_amount

        if not is_positive_integer(work_amount):
            raise TypeError("work_amount me be a positive integer")
        self.priority = priority

        assertions = [
            self.start + self.duration == self.end,
            self.duration == duration,
            self.start >= 0,
        ]

        self.set_assertions(assertions)
Esempio n. 2
0
    def __init__(
        self,
        name: str,
        min_duration: Optional[int] = 0,
        max_duration: Optional[int] = None,
        allowed_durations: Optional[List[int]] = None,
        work_amount: Optional[int] = 0,
        priority: Optional[int] = 1,
        optional: Optional[bool] = False,
    ):
        super().__init__(name, optional)

        # allowed durations and min/max are exclusive
        if is_list_of_positive_integers(allowed_durations):
            all_cstr = []
            for duration in allowed_durations:
                all_cstr.append(self.duration == duration)
            self.append_z3_assertion(Or(all_cstr))
        else:
            if is_positive_integer(max_duration):
                self.append_z3_assertion(self.duration <= max_duration)
            elif max_duration is not None:
                raise TypeError(
                    "length_as_most should either be a positive integer or None"
                )

            if not is_positive_integer(min_duration):
                raise TypeError("min_duration must be a positive integer")

            if not is_positive_integer(work_amount):
                raise TypeError("work_amount must be a positive integer")

        self.min_duration = min_duration
        self.max_duration = max_duration
        self.allowed_durations = allowed_durations
        self.work_amount = work_amount
        self.priority = priority

        assertions = [
            self.start + self.duration == self.end,
            self.start >= 0,
            self.duration >= min_duration,
        ]

        if max_duration is not None:
            assertions.append(self.duration <= max_duration)

        if min_duration is not None:
            assertions.append(self.duration >= min_duration)

        self.set_assertions(assertions)
Esempio n. 3
0
    def __init__(
        self,
        name: str,
        min_duration: Optional[int] = 0,
        max_duration: Optional[int] = None,
        work_amount: Optional[int] = 0,
        priority: Optional[int] = 1,
        optional: Optional[bool] = False,
    ):
        super().__init__(name, optional)

        if is_positive_integer(max_duration):
            self.add_assertion(self.duration <= max_duration)
        elif max_duration is not None:
            raise TypeError(
                "length_as_most should either be a positive integer or None"
            )

        if not is_positive_integer(min_duration):
            raise TypeError("min_duration must be a positive integer")

        if not is_positive_integer(work_amount):
            raise TypeError("work_amount me be a positive integer")

        self.min_duration = min_duration
        self.max_duration = max_duration
        self.work_amount = work_amount
        self.priority = priority

        assertions = [
            self.start + self.duration == self.end,
            self.start >= 0,
            self.duration >= min_duration,
        ]

        if max_duration is not None:
            assertions.append(self.duration <= max_duration)

        if min_duration is not None:
            assertions.append(self.duration >= min_duration)

        self.set_assertions(assertions)
Esempio n. 4
0
 def test_is_positive_integer(self):
     self.assertTrue(is_positive_integer(1))
     self.assertTrue(is_positive_integer(0))
     self.assertTrue(is_positive_integer(7))
     self.assertFalse(is_positive_integer(7.5))
     self.assertFalse(is_positive_integer(-1))
     self.assertFalse(is_positive_integer(-0.3))
Esempio n. 5
0
    def __init__(
        self,
        name: str,
        size: int,
        productivity: Optional[int] = 1,
        cost: Optional[int] = None,
    ) -> None:
        super().__init__(name)

        if not (isinstance(size, int) and size >= 2):
            raise ValueError("CumulativeWorker 'size' attribute must be >=2.")
        self.size = size

        if not is_positive_integer(productivity):
            raise TypeError("productivity must be an integer >= 0")
        self.productivity = productivity

        if cost is None:
            self.cost = None

        elif not isinstance(cost, _Cost):
            raise TypeError("cost must be a _Cost instance")
        self.cost_defined_value = cost

        # productivity and cost_per_period are distributed over
        # individual workers
        # for example, a productivty of 7 for a size of 3 will be distributed
        # as 3 on worker 1, 2 on worker 2 and 2 on worker 3. Same for cost_per_periods
        productivities = _distribute_p_over_n(productivity, size)

        costs_per_period = _distribute_p_over_n(cost, size)

        # we create as much elementary workers as the cumulative size
        self.cumulative_workers = [
            Worker(
                "%s_CumulativeWorker_%i" % (name, i + 1),
                productivity=productivities[i],
                cost=costs_per_period[i],
            ) for i in range(size)
        ]

        ps_context.main_context.add_resource_cumulative_worker(self)
Esempio n. 6
0
    def __init__(self,
                 name: str,
                 productivity: Optional[int] = 1,
                 cost: Optional[int] = None) -> None:
        super().__init__(name)
        if not is_positive_integer(productivity):
            raise TypeError("productivity must be an integer >= 0")
        if cost is None:
            self.cost = None
        elif not isinstance(cost, _Cost):
            raise TypeError("cost must be a _Cost instance")
        self.productivity = productivity
        self.cost = cost

        # only worker are add to the main context, not SelectWorkers
        # add this resource to the current context
        if ps_context.main_context is None:
            raise AssertionError(
                "No context available. First create a SchedulingProblem")
        ps_context.main_context.add_resource(self)
Esempio n. 7
0
 def __init__(self, value: int) -> None:
     super().__init__()
     if not is_positive_integer(value):
         raise ValueError("the cost per period must be a positive integer")
     self.value = value
     self.f = lambda x: value