Generated on Thu Mar 22 10:39:45 2012 for Gecode by doxygen 1.6.3

seq-u.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *     Christian Schulte <schulte@gecode.org>
00006  *
00007  *  Contributing authors:
00008  *     Gabor Szokoli <szokoli@gecode.org>
00009  *
00010  *  Copyright:
00011  *     Guido Tack, 2004
00012  *     Christian Schulte, 2004
00013  *     Gabor Szokoli, 2004
00014  *
00015  *  Last modified:
00016  *     $Date: 2011-05-23 16:48:31 +0200 (Mon, 23 May 2011) $ by $Author: tack $
00017  *     $Revision: 12018 $
00018  *
00019  *  This file is part of Gecode, the generic constraint
00020  *  development environment:
00021  *     http://www.gecode.org
00022  *
00023  *  Permission is hereby granted, free of charge, to any person obtaining
00024  *  a copy of this software and associated documentation files (the
00025  *  "Software"), to deal in the Software without restriction, including
00026  *  without limitation the rights to use, copy, modify, merge, publish,
00027  *  distribute, sublicense, and/or sell copies of the Software, and to
00028  *  permit persons to whom the Software is furnished to do so, subject to
00029  *  the following conditions:
00030  *
00031  *  The above copyright notice and this permission notice shall be
00032  *  included in all copies or substantial portions of the Software.
00033  *
00034  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00035  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00036  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00037  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00038  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00039  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00040  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00041  *
00042  */
00043 
00044 #include <gecode/set/sequence.hh>
00045 
00046 namespace Gecode { namespace Set { namespace Sequence {
00047 
00048   /*
00049    * "Sequenced union" propagator
00050    *
00051    */
00052 
00053   Actor*
00054   SeqU::copy(Space& home, bool share) {
00055     return new (home) SeqU(home,share,*this);
00056   }
00057 
00058   ExecStatus
00059   SeqU::propagateSeqUnion(Space& home,
00060                           bool& modified, ViewArray<SetView>& x,
00061                           SetView& y) {
00062     Region r(home);
00063     GlbRanges<SetView>* XLBs = r.alloc<GlbRanges<SetView> >(x.size());
00064     for (int i=x.size(); i--; ){
00065       GlbRanges<SetView> lb(x[i]);
00066       XLBs[i]=lb;
00067     }
00068     Iter::Ranges::NaryAppend<GlbRanges<SetView> > u(XLBs,x.size());
00069     GECODE_ME_CHECK_MODIFIED(modified, y.includeI(home,u));
00070 
00071     GLBndSet before(home);
00072     for (int i=0; i<x.size(); i++) {
00073       LubRanges<SetView> xiub(x[i]);
00074       before.includeI(home, xiub);
00075       BndSetRanges beforeR(before);
00076       GlbRanges<SetView> ylb(y);
00077       Iter::Ranges::Diff<GlbRanges<SetView>, BndSetRanges> diff(ylb, beforeR);
00078       if (diff()) {
00079         GECODE_ME_CHECK_MODIFIED(modified, x[i].exclude(home, diff.min(),
00080                                                         Limits::max));
00081       }
00082     }
00083     before.dispose(home);
00084 
00085     GLBndSet after(home);
00086     for (int i=x.size(); i--; ) {
00087       LubRanges<SetView> xiub(x[i]);
00088       after.includeI(home, xiub);
00089       BndSetRanges afterR(after);
00090       GlbRanges<SetView> ylb(y);
00091       Iter::Ranges::Diff<GlbRanges<SetView>, BndSetRanges> diff(ylb, afterR);
00092       if (diff()) {
00093         int max = diff.max();
00094         for (; diff(); ++diff)
00095           max = diff.max();
00096         GECODE_ME_CHECK_MODIFIED(modified, x[i].exclude(home,
00097                                                         Limits::min,
00098                                                         max));
00099       }
00100     }
00101     after.dispose(home);
00102 
00103     return ES_FIX;
00104   }
00105 
00106   //Enforces sequentiality and ensures y contains union of Xi lower bounds.
00107   ExecStatus
00108   SeqU::propagate(Space& home, const ModEventDelta& med) {
00109     ModEvent me0 = SetView::me(med);
00110     bool ubevent = Rel::testSetEventUB(me0);
00111     bool anybevent = Rel::testSetEventAnyB(me0);
00112     bool cardevent = Rel::testSetEventCard(me0);
00113 
00114     bool modified = false;
00115     bool assigned=false;
00116     bool oldModified = false;
00117 
00118     do {
00119       oldModified = modified;
00120       modified = false;
00121 
00122       if (oldModified || modified || anybevent || cardevent)
00123         GECODE_ES_CHECK(propagateSeq(home,modified,assigned,x));
00124       if (oldModified || modified || anybevent)
00125         GECODE_ES_CHECK(propagateSeqUnion(home,modified,x,y));
00126       if (oldModified || modified || ubevent)
00127         GECODE_ES_CHECK(RelOp::unionNXiUB(home,modified,x,y,unionOfDets));
00128       if (oldModified || modified || ubevent)
00129         GECODE_ES_CHECK(RelOp::partitionNYUB(home,modified,x,y,unionOfDets));
00130       if (oldModified || modified || anybevent)
00131         GECODE_ES_CHECK(RelOp::partitionNXiLB(home,modified,x,y,unionOfDets));
00132       if (oldModified || modified || cardevent || ubevent)
00133         GECODE_ES_CHECK(RelOp::partitionNCard(home,modified,x,y,unionOfDets));
00134 
00135     } while (modified);
00136 
00137     for (int i=x.size(); i--;)
00138       if (!x[i].assigned())
00139         return ES_FIX;
00140     return home.ES_SUBSUMED(*this);
00141   }
00142 
00143 }}}
00144 
00145 // STATISTICS: set-prop