Skip to content

Commit

Permalink
Merge pull request Pyomo#3227 from emma58/sequence-var
Browse files Browse the repository at this point in the history
contrib.cp: Adding SequenceVar and other logical expressions for scheduling
  • Loading branch information
mrmundt committed May 8, 2024
2 parents 34b15d8 + 7c0741a commit a44a832
Show file tree
Hide file tree
Showing 17 changed files with 1,392 additions and 106 deletions.
13 changes: 13 additions & 0 deletions pyomo/contrib/cp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@
IntervalVarPresence,
)
from pyomo.contrib.cp.repn.docplex_writer import DocplexWriter, CPOptimizerSolver
from pyomo.contrib.cp.sequence_var import SequenceVar
from pyomo.contrib.cp.scheduling_expr.sequence_expressions import (
no_overlap,
first_in_sequence,
last_in_sequence,
before_in_sequence,
predecessor_to,
)
from pyomo.contrib.cp.scheduling_expr.scheduling_logic import (
alternative,
spans,
synchronize,
)
from pyomo.contrib.cp.scheduling_expr.step_function_expressions import (
AlwaysIn,
Step,
Expand Down
15 changes: 11 additions & 4 deletions pyomo/contrib/cp/interval_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from pyomo.common.collections import ComponentSet
from pyomo.common.pyomo_typing import overload
from pyomo.contrib.cp.scheduling_expr.scheduling_logic import SpanExpression
from pyomo.contrib.cp.scheduling_expr.precedence_expressions import (
BeforeExpression,
AtExpression,
Expand All @@ -24,6 +25,7 @@
from pyomo.core.base.indexed_component import IndexedComponent, UnindexedComponent_set
from pyomo.core.base.initializer import BoundInitializer, Initializer
from pyomo.core.expr import GetItemExpression
from pyomo.core.expr.logical_expr import _flattened


class IntervalVarTimePoint(ScalarVar):
Expand All @@ -49,15 +51,15 @@ class IntervalVarStartTime(IntervalVarTimePoint):
"""This class defines a single variable denoting a start time point
of an IntervalVar"""

def __init__(self):
def __init__(self, *args, **kwd):
super().__init__(domain=Integers, ctype=IntervalVarStartTime)


class IntervalVarEndTime(IntervalVarTimePoint):
"""This class defines a single variable denoting an end time point
of an IntervalVar"""

def __init__(self):
def __init__(self, *args, **kwd):
super().__init__(domain=Integers, ctype=IntervalVarEndTime)


Expand All @@ -67,7 +69,7 @@ class IntervalVarLength(ScalarVar):

__slots__ = ()

def __init__(self):
def __init__(self, *args, **kwd):
super().__init__(domain=Integers, ctype=IntervalVarLength)

def get_associated_interval_var(self):
Expand All @@ -80,7 +82,9 @@ class IntervalVarPresence(ScalarBooleanVar):

__slots__ = ()

def __init__(self):
def __init__(self, *args, **kwd):
# TODO: adding args and kwd above made Reference work, but we
# probably shouldn't just swallow them, right?
super().__init__(ctype=IntervalVarPresence)

def get_associated_interval_var(self):
Expand Down Expand Up @@ -122,6 +126,9 @@ def optional(self, val):
else:
self.is_present.fix(True)

def spans(self, *args):
return SpanExpression([self] + list(_flattened(args)))


@ModelComponentFactory.register("Interval variables for scheduling.")
class IntervalVar(Block):
Expand Down
Loading

0 comments on commit a44a832

Please sign in to comment.