Generated on Thu Mar 16 2017 03:24:19 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  * Last modified:
12  * $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
13  * $Revision: 14967 $
14  *
15  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 #include <algorithm>
41 
42 namespace Gecode { namespace Int { namespace Cumulative {
43 
44  template<class OptTask, class Cap, class PL>
47  : TaskProp<OptTask,PL>(home,t), c(c0) {
48  c.subscribe(home,*this,PC_INT_BND);
49  }
50 
51  template<class OptTask, class Cap, class PL>
55  : TaskProp<OptTask,PL>(home,shared,p) {
56  c.update(home,shared,p.c);
57  }
58 
59  template<class OptTask, class Cap, class PL>
62  // Capacity must be nonnegative
63  GECODE_ME_CHECK(c.gq(home, 0));
64  // Check for overload by single task and remove excluded tasks
65  int n=t.size(), m=0;
66  for (int i=n; i--; ) {
67  if (t[i].c() > c.max())
68  GECODE_ME_CHECK(t[i].excluded(home));
69  if (t[i].excluded())
70  t[i]=t[--n];
71  else if (t[i].mandatory())
72  m++;
73  }
74  t.size(n);
75  if (t.size() < 2) {
76  if (t.size() == 1) {
77  if (t[0].mandatory()) {
78  GECODE_ME_CHECK(c.gq(home, t[0].c()));
79  return ES_OK;
80  } else if (c.min() >= t[0].c()) {
81  return ES_OK;
82  }
83  } else {
84  return ES_OK;
85  }
86  }
87  if (c.assigned() && (c.val() == 1)) {
89  for (int i=t.size(); i--; )
90  mt[i]=t[i];
92  ::post(home,mt);
93  }
94  if (m == t.size()) {
96  for (int i=m; i--; )
97  mt[i].init(t[i]);
99  ::post(home,c,mt);
100  }
101  (void) new (home) OptProp<OptTask,Cap,PL>(home,c,t);
102  return ES_OK;
103  }
104 
105  template<class OptTask, class Cap, class PL>
106  Actor*
108  return new (home) OptProp<OptTask,Cap,PL>(home,share,*this);
109  }
110 
111  template<class OptTask, class Cap, class PL>
112  forceinline size_t
114  (void) TaskProp<OptTask,PL>::dispose(home);
115  c.cancel(home,*this,PC_INT_BND);
116  return sizeof(*this);
117  }
118 
119  template<class OptTask, class Cap, class PL>
120  ExecStatus
122  // Did one of the Boolean views change?
123  if (BoolView::me(med) == ME_BOOL_VAL)
124  GECODE_ES_CHECK((purge<OptTask,PL>(home,*this,t,c)));
125 
126  // Only bounds changes?
127  if (IntView::me(med) != ME_INT_DOM)
128  GECODE_ES_CHECK(overload(home,c.max(),t));
129 
130  if (PL::basic)
131  GECODE_ES_CHECK(timetabling(home,*this,c,t));
132 
133  if (PL::advanced) {
134  // Partition into mandatory and optional activities
135  int n = t.size();
136  int i=0, j=n-1;
137  while (true) {
138  while ((i < n) && t[i].mandatory()) i++;
139  while ((j >= 0) && !t[j].mandatory()) j--;
140  if (i >= j) break;
141  std::swap(t[i],t[j]);
142  }
143 
144  if (i > 1) {
145  // Truncate array to only contain mandatory tasks
146  t.size(i);
147  GECODE_ES_CHECK(edgefinding(home,c.max(),t));
148  // Restore to also include optional tasks
149  t.size(n);
150  }
151  }
152 
153  if (Cap::varderived() && c.assigned() && c.val()==1) {
154  // Check that tasks do not overload resource
155  for (int i=t.size(); i--; )
156  if (t[i].c() > 1)
157  GECODE_ME_CHECK(t[i].excluded(home));
158  // Rewrite to unary resource constraint
160  for (int i=t.size(); i--;)
161  ut[i]=t[i];
162  GECODE_REWRITE(*this,
164  ::post(home(*this),ut)));
165  }
166 
167  if (!PL::basic && c.assigned())
168  GECODE_ES_CHECK(subsumed(home,*this,c.val(),t));
169 
170  return ES_NOFIX;
171  }
172 
173 }}}
174 
175 // STATISTICS: int-prop
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:120
NodeType t
Type of node.
Definition: bool-expr.cpp:234
ExecStatus subsumed(Space &home, Propagator &p, int c, TaskArray< Task > &t)
Check for subsumption (all tasks must be assigned)
Definition: subsumption.hpp:42
ExecStatus overload(Space &home, int c, TaskArray< ManTask > &t)
Check mandatory tasks t for overload.
Definition: overload.hpp:45
Propagator for tasks
Definition: task.hh:428
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: opt-prop.hpp:113
Scheduling propagator for cumulative resource with optional tasks.
Definition: cumulative.hh:733
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: opt-prop.hpp:121
Computation spaces.
Definition: core.hpp:1672
Traits class for mapping tasks to task views.
Definition: task.hh:161
Base-class for both propagators and branchers.
Definition: core.hpp:682
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition: macros.hpp:95
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
virtual Actor * copy(Space &home, bool share)
Perform copying during cloning.
Definition: opt-prop.hpp:107
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:1022
OptProp(Home home, Cap c, TaskArray< OptTask > &t)
Constructor for creation.
Definition: opt-prop.hpp:46
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:56
Scheduling propagator for unary resource with optional tasks
Definition: unary.hh:818
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:536
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
Definition: view.hpp:502
#define forceinline
Definition: config.hpp:173
Execution is okay.
Definition: core.hpp:540
Propagation has not computed fixpoint.
Definition: core.hpp:539
Scheduling propagator for cumulative resource with mandatory tasks.
Definition: cumulative.hh:706
bool shared(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:690
Gecode toplevel namespace
TaskArray< OptTask > t
Tasks.
Definition: task.hh:431
int ModEventDelta
Modification event deltas.
Definition: core.hpp:169
Home class for posting propagators
Definition: core.hpp:905
Cap c
Resource capacity.
Definition: cumulative.hh:737
ExecStatus edgefinding(Space &home, int c, TaskViewArray< TaskView > &t)
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:67
static ExecStatus post(Home home, Cap c, TaskArray< OptTask > &t)
Post propagator that schedules tasks on cumulative resource.
Definition: opt-prop.hpp:61