Generated on Fri Jan 28 2022 04:43:06 for Gecode by doxygen 1.8.13
opt-prop.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  * Guido Tack <tack@gecode.org>
6  *
7  * Copyright:
8  * Christian Schulte, 2009
9  * Guido Tack, 2010
10  *
11  * This file is part of Gecode, the generic constraint
12  * development environment:
13  * http://www.gecode.org
14  *
15  * Permission is hereby granted, free of charge, to any person obtaining
16  * a copy of this software and associated documentation files (the
17  * "Software"), to deal in the Software without restriction, including
18  * without limitation the rights to use, copy, modify, merge, publish,
19  * distribute, sublicense, and/or sell copies of the Software, and to
20  * permit persons to whom the Software is furnished to do so, subject to
21  * the following conditions:
22  *
23  * The above copyright notice and this permission notice shall be
24  * included in all copies or substantial portions of the Software.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33  *
34  */
35 
36 #include <algorithm>
37 
38 namespace Gecode { namespace Int { namespace Cumulative {
39 
40  template<class OptTask, class Cap, class PL>
43  : TaskProp<OptTask,PL>(home,t), c(c0) {
44  c.subscribe(home,*this,PC_INT_BND);
45  }
46 
47  template<class OptTask, class Cap, class PL>
50  : TaskProp<OptTask,PL>(home,p) {
51  c.update(home,p.c);
52  }
53 
54  template<class OptTask, class Cap, class PL>
57  // Capacity must be nonnegative
58  GECODE_ME_CHECK(c.gq(home, 0));
59  // Check for overload by single task and remove excluded tasks
60  int n=t.size(), m=0;
61  for (int i=n; i--; ) {
62  if (t[i].c() > c.max())
63  GECODE_ME_CHECK(t[i].excluded(home));
64  if (t[i].excluded())
65  t[i]=t[--n];
66  else if (t[i].mandatory())
67  m++;
68  }
69  t.size(n);
70  if (t.size() < 2) {
71  if (t.size() == 1) {
72  if (t[0].mandatory()) {
73  GECODE_ME_CHECK(c.gq(home, t[0].c()));
74  return ES_OK;
75  } else if (c.min() >= t[0].c()) {
76  return ES_OK;
77  }
78  } else {
79  return ES_OK;
80  }
81  }
82  if (c.assigned() && (c.val() == 1)) {
84  for (int i=0; i<t.size(); i++)
85  mt[i]=t[i];
87  ::post(home,mt);
88  }
89  if (m == t.size()) {
91  for (int i=0; i<m; i++)
92  mt[i].init(t[i]);
94  ::post(home,c,mt);
95  }
96  (void) new (home) OptProp<OptTask,Cap,PL>(home,c,t);
97  return ES_OK;
98  }
99 
100  template<class OptTask, class Cap, class PL>
101  Actor*
103  return new (home) OptProp<OptTask,Cap,PL>(home,*this);
104  }
105 
106  template<class OptTask, class Cap, class PL>
107  forceinline size_t
109  (void) TaskProp<OptTask,PL>::dispose(home);
110  c.cancel(home,*this,PC_INT_BND);
111  return sizeof(*this);
112  }
113 
114  template<class OptTask, class Cap, class PL>
115  ExecStatus
117  // Did one of the Boolean views change?
118  if (BoolView::me(med) == ME_BOOL_VAL)
119  GECODE_ES_CHECK((purge<OptTask,PL>(home,*this,t,c)));
120 
121  // Only bounds changes?
122  if (IntView::me(med) != ME_INT_DOM)
123  GECODE_ES_CHECK(overload(home,c.max(),t));
124 
125  if (PL::basic)
126  GECODE_ES_CHECK(timetabling(home,*this,c,t));
127 
128  if (PL::advanced) {
129  // Partition into mandatory and optional activities
130  int n = t.size();
131  int i=0, j=n-1;
132  while (true) {
133  while ((i < n) && t[i].mandatory()) i++;
134  while ((j >= 0) && !t[j].mandatory()) j--;
135  if (i >= j) break;
136  std::swap(t[i],t[j]);
137  }
138 
139  if (i > 1) {
140  // Truncate array to only contain mandatory tasks
141  t.size(i);
142  GECODE_ES_CHECK(edgefinding(home,c.max(),t));
143  // Restore to also include optional tasks
144  t.size(n);
145  }
146  }
147 
148  if (Cap::varderived() && c.assigned() && c.val()==1) {
149  // Check that tasks do not overload resource
150  for (int i=0; i<t.size(); i++)
151  if (t[i].c() > 1)
152  GECODE_ME_CHECK(t[i].excluded(home));
153  // Rewrite to unary resource constraint
155  for (int i=0; i<t.size(); i++)
156  ut[i]=t[i];
157  GECODE_REWRITE(*this,
159  ::post(home(*this),ut)));
160  }
161 
162  if (!PL::basic && c.assigned())
163  GECODE_ES_CHECK(subsumed(home,*this,c.val(),t));
164 
165  return ES_NOFIX;
166  }
167 
168 }}}
169 
170 // STATISTICS: int-prop
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:116
NodeType t
Type of node.
Definition: bool-expr.cpp:230
ExecStatus subsumed(Space &home, Propagator &p, int c, TaskArray< Task > &t)
Check for subsumption (all tasks must be assigned)
Definition: subsumption.hpp:38
ExecStatus overload(Space &home, int c, TaskArray< ManTask > &t)
Check mandatory tasks t for overload.
Definition: overload.hpp:41
Propagator for tasks
Definition: task.hh:424
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: opt-prop.hpp:108
Scheduling propagator for cumulative resource with optional tasks.
Definition: cumulative.hh:729
#define forceinline
Definition: config.hpp:185
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: opt-prop.hpp:116
Computation spaces.
Definition: core.hpp:1701
Traits class for mapping tasks to task views.
Definition: task.hh:157
Base-class for both propagators and branchers.
Definition: core.hpp:627
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition: macros.hpp:91
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Gecode::IntArgs i({1, 2, 3, 4})
const Gecode::PropCond PC_INT_BND
Propagate when minimum or maximum of a view changes.
Definition: var-type.hpp:91
ModEventDelta med
A set of modification events (used during propagation)
Definition: core.hpp:1034
OptProp(Home home, Cap c, TaskArray< OptTask > &t)
Constructor for creation.
Definition: opt-prop.hpp:42
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:52
virtual Actor * copy(Space &home)
Perform copying during cloning.
Definition: opt-prop.hpp:102
Scheduling propagator for unary resource with optional tasks
Definition: unary.hh:814
const Gecode::ModEvent ME_INT_DOM
Domain operation has changed the domain.
Definition: var-type.hpp:72
ExecStatus timetabling(Space &home, Propagator &p, Cap c, TaskArray< Task > &t)
Perform time-tabling propagation.
ExecStatus
Definition: core.hpp:471
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
Definition: view.hpp:552
Execution is okay.
Definition: core.hpp:475
Propagation has not computed fixpoint.
Definition: core.hpp:474
Scheduling propagator for cumulative resource with mandatory tasks.
Definition: cumulative.hh:702
Gecode toplevel namespace
TaskArray< OptTask > t
Tasks.
Definition: task.hh:427
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
Home class for posting propagators
Definition: core.hpp:853
Cap c
Resource capacity.
Definition: cumulative.hh:733
ExecStatus edgefinding(Space &home, int c, TaskViewArray< TaskView > &t)
IntRelType swap(IntRelType irt)
Return swapped relation type of irt.
Definition: irt.hpp:37
const Gecode::ModEvent ME_BOOL_VAL
Domain operation has resulted in a value (assigned variable)
Definition: var-type.hpp:116
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:63
static ExecStatus post(Home home, Cap c, TaskArray< OptTask > &t)
Post propagator that schedules tasks on cumulative resource.
Definition: opt-prop.hpp:56