~ubuntu-branches/ubuntu/natty/gecode/natty

« back to all changes in this revision

Viewing changes to set/var/imp.cc

  • Committer: Bazaar Package Importer
  • Author(s): Kari Pahula
  • Date: 2005-12-24 07:51:25 UTC
  • Revision ID: james.westby@ubuntu.com-20051224075125-klkiqofvbfvusfvt
Tags: upstream-1.0.0.dfsg.1
ImportĀ upstreamĀ versionĀ 1.0.0.dfsg.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Main authors:
 
3
 *     Guido Tack <tack@gecode.org>
 
4
 *     Christian Schulte <schulte@gecode.org>
 
5
 *
 
6
 *  Copyright:
 
7
 *     Guido Tack, 2004
 
8
 *     Christian Schulte, 2004
 
9
 *
 
10
 *  Last modified:
 
11
 *     $Date: 2005-10-31 11:02:00 +0100 (Mon, 31 Oct 2005) $ by $Author: schulte $
 
12
 *     $Revision: 2428 $
 
13
 *
 
14
 *  This file is part of Gecode, the generic constraint
 
15
 *  development environment:
 
16
 *     http://www.gecode.org
 
17
 *
 
18
 *  See the file "LICENSE" for information on usage and
 
19
 *  redistribution of this file, and for a
 
20
 *     DISCLAIMER OF ALL WARRANTIES.
 
21
 *
 
22
 */
 
23
 
 
24
#include "set.hh"
 
25
 
 
26
namespace Gecode { namespace Set {
 
27
 
 
28
  /*
 
29
   * "Standard" tell operations
 
30
   *
 
31
   */
 
32
  ModEvent
 
33
  SetVarImp::cardMin_full(Space* home,unsigned int newMin) {
 
34
    ModEvent me = ME_SET_CARD;
 
35
    if (_cardMin == _cardMax)
 
36
      me = checkLubCardAssigned(home,ME_SET_CARD);
 
37
    if (!me_failed(me))
 
38
      notify(home, me);
 
39
    return me;
 
40
  }
 
41
 
 
42
  ModEvent
 
43
  SetVarImp::cardMax_full(Space* home,unsigned int newMax) {
 
44
    ModEvent me = ME_SET_CARD;
 
45
    if (_cardMin == _cardMax)
 
46
      me = checkGlbCardAssigned(home,ME_SET_CARD);
 
47
    if (!me_failed(me))
 
48
      notify(home, me);
 
49
    return me;
 
50
  }
 
51
 
 
52
  ModEvent
 
53
  SetVarImp::processLubChange(Space* home) {
 
54
    if (!boundsConsistent()) {
 
55
      return ME_SET_FAILED;
 
56
    }
 
57
    ModEvent me;
 
58
    if (_cardMax > lub.size()) {
 
59
      _cardMax = lub.size();
 
60
      if (cardMin() > cardMax())
 
61
        return ME_SET_FAILED;
 
62
      if (assigned()) {
 
63
        lub.linkTo(home, glb);
 
64
        me = ME_SET_VAL;
 
65
      } else {
 
66
        me = checkLubCardAssigned(home, ME_SET_CLUB);
 
67
      }
 
68
    } else {
 
69
      me = checkLubCardAssigned(home, ME_SET_LUB);
 
70
    }
 
71
    if (!me_failed(me))
 
72
      notify(home, me);
 
73
    return me;
 
74
  }
 
75
 
 
76
  ModEvent
 
77
  SetVarImp::processGlbChange(Space* home) {
 
78
    if (!boundsConsistent())
 
79
      return ME_SET_FAILED;
 
80
    ModEvent me;
 
81
    if (_cardMin < glb.size()) {
 
82
      _cardMin = glb.size();
 
83
      if (cardMin() > cardMax())
 
84
        return ME_SET_FAILED;
 
85
      if (assigned()) {
 
86
        lub.linkTo(home, glb);
 
87
        me = ME_SET_VAL;
 
88
      } else {
 
89
        me = checkGlbCardAssigned(home, ME_SET_CGLB);
 
90
      }
 
91
    } else {
 
92
      me = checkGlbCardAssigned(home, ME_SET_GLB);
 
93
    }
 
94
    if (me!=ME_SET_FAILED)
 
95
      notify(home, me);
 
96
    return me;
 
97
  }
 
98
 
 
99
  /*
 
100
   * Copying variables
 
101
   *
 
102
   */
 
103
 
 
104
  forceinline
 
105
  SetVarImp::SetVarImp(Space* home, bool share, SetVarImp& x)
 
106
    : Variable<VTI_SET,PC_SET_ANY>(home,share,x),
 
107
      _cardMin(x._cardMin), _cardMax(x._cardMax) {
 
108
    lub.update(home, x.lub);
 
109
    if (x.assigned()) {
 
110
      glb.linkTo(home,lub);
 
111
    } else {
 
112
      glb.update(home,x.glb);
 
113
    }
 
114
  }
 
115
 
 
116
 
 
117
  SetVarImp*
 
118
  SetVarImp::perform_copy(Space* home, bool share) {
 
119
    return new (home) SetVarImp(home,share,*this);
 
120
  }
 
121
 
 
122
 
 
123
  /*
 
124
   * Finite Integer Set variable processor
 
125
   *
 
126
   */
 
127
 
 
128
  forceinline
 
129
  SetVarImp::Processor::Processor(void) {
 
130
    // Combination of modification events
 
131
    mec(ME_SET_CARD, ME_SET_LUB,  ME_SET_CLUB);
 
132
    mec(ME_SET_CARD, ME_SET_GLB,  ME_SET_CGLB);
 
133
    mec(ME_SET_CARD, ME_SET_BB,   ME_SET_CBB);
 
134
    mec(ME_SET_CARD, ME_SET_CLUB, ME_SET_CLUB);
 
135
    mec(ME_SET_CARD, ME_SET_CGLB, ME_SET_CGLB);
 
136
    mec(ME_SET_CARD, ME_SET_CBB,  ME_SET_CBB);
 
137
 
 
138
    mec(ME_SET_LUB,  ME_SET_GLB,  ME_SET_BB);
 
139
    mec(ME_SET_LUB,  ME_SET_BB,   ME_SET_BB);
 
140
    mec(ME_SET_LUB,  ME_SET_CLUB, ME_SET_CLUB);
 
141
    mec(ME_SET_LUB,  ME_SET_CGLB, ME_SET_CBB);
 
142
    mec(ME_SET_LUB,  ME_SET_CBB,  ME_SET_CBB);
 
143
 
 
144
    mec(ME_SET_GLB,  ME_SET_BB,   ME_SET_BB);
 
145
    mec(ME_SET_GLB,  ME_SET_CLUB, ME_SET_CBB);
 
146
    mec(ME_SET_GLB,  ME_SET_CGLB, ME_SET_CGLB);
 
147
    mec(ME_SET_GLB,  ME_SET_CBB,  ME_SET_CBB);
 
148
 
 
149
    mec(ME_SET_BB,   ME_SET_CLUB, ME_SET_CBB);
 
150
    mec(ME_SET_BB,   ME_SET_CGLB, ME_SET_CBB);
 
151
    mec(ME_SET_BB,   ME_SET_CBB,  ME_SET_CBB);
 
152
 
 
153
    mec(ME_SET_CLUB, ME_SET_CGLB, ME_SET_CBB);
 
154
    mec(ME_SET_CLUB, ME_SET_CBB,  ME_SET_CBB);
 
155
 
 
156
    mec(ME_SET_CGLB, ME_SET_CBB,  ME_SET_CBB);
 
157
 
 
158
    // Mapping between modification events and propagation conditions
 
159
    mepc(ME_SET_CARD, PC_SET_CARD); mepc(ME_SET_CARD, PC_SET_CGLB);
 
160
    mepc(ME_SET_CARD, PC_SET_CLUB); mepc(ME_SET_CARD, PC_SET_ANY);
 
161
 
 
162
    mepc(ME_SET_LUB,  PC_SET_CLUB); mepc(ME_SET_LUB,  PC_SET_ANY);
 
163
 
 
164
    mepc(ME_SET_GLB,  PC_SET_CGLB); mepc(ME_SET_GLB,  PC_SET_ANY);
 
165
 
 
166
    mepc(ME_SET_BB,   PC_SET_CGLB); mepc(ME_SET_BB,   PC_SET_CLUB);
 
167
    mepc(ME_SET_BB,   PC_SET_ANY);
 
168
 
 
169
    mepc(ME_SET_CLUB, PC_SET_CARD); mepc(ME_SET_CLUB, PC_SET_CGLB);
 
170
    mepc(ME_SET_CLUB, PC_SET_CLUB); mepc(ME_SET_CLUB, PC_SET_ANY);
 
171
 
 
172
    mepc(ME_SET_CGLB, PC_SET_CARD); mepc(ME_SET_CGLB, PC_SET_CGLB);
 
173
    mepc(ME_SET_CGLB, PC_SET_CLUB); mepc(ME_SET_CGLB, PC_SET_ANY);
 
174
 
 
175
    mepc(ME_SET_CBB,  PC_SET_CARD); mepc(ME_SET_CBB,  PC_SET_CGLB);
 
176
    mepc(ME_SET_CBB,  PC_SET_CLUB); mepc(ME_SET_CBB,  PC_SET_ANY);
 
177
    // Transfer to kernel
 
178
    enter();
 
179
  }
 
180
 
 
181
  SetVarImp::Processor SetVarImp::svp;
 
182
 
 
183
 
 
184
  /*
 
185
   * Subscribing to variables
 
186
   *
 
187
   */
 
188
 
 
189
  void
 
190
  SetVarImp::subscribe(Space* home, Propagator* p, PropCond pc) {
 
191
    Variable<VTI_SET,PC_SET_ANY>::subscribe(home,p,pc,
 
192
                                            assigned(), ME_SET_CBB);
 
193
  }
 
194
 
 
195
}}
 
196
 
 
197
// STATISTICS: set-var
 
198