Generated on Thu Apr 11 13:58:58 2019 for Gecode by doxygen 1.6.3

channel.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *     Guido Tack <tack@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2006
00009  *     Guido Tack, 2011
00010  *
00011  *  This file is part of Gecode, the generic constraint
00012  *  development environment:
00013  *     http://www.gecode.org
00014  *
00015  *  Permission is hereby granted, free of charge, to any person obtaining
00016  *  a copy of this software and associated documentation files (the
00017  *  "Software"), to deal in the Software without restriction, including
00018  *  without limitation the rights to use, copy, modify, merge, publish,
00019  *  distribute, sublicense, and/or sell copies of the Software, and to
00020  *  permit persons to whom the Software is furnished to do so, subject to
00021  *  the following conditions:
00022  *
00023  *  The above copyright notice and this permission notice shall be
00024  *  included in all copies or substantial portions of the Software.
00025  *
00026  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00027  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00028  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00029  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00030  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00031  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00032  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00033  *
00034  */
00035 
00036 #include <gecode/int/channel.hh>
00037 
00038 namespace Gecode {
00039 
00040   void
00041   channel(Home home, const IntVarArgs& x, int xoff,
00042           const IntVarArgs& y, int yoff,
00043           IntPropLevel ipl) {
00044     using namespace Int;
00045     using namespace Channel;
00046     int n = x.size();
00047     if (n != y.size())
00048       throw ArgumentSizeMismatch("Int::channel");
00049     if (same(x) || same(y))
00050       throw ArgumentSame("Int::channel");
00051     Limits::check(xoff,"Int::channel");
00052     Limits::check(yoff,"Int::channel");
00053     if ((xoff < 0) || (yoff < 0))
00054       throw OutOfLimits("Int::channel");
00055     GECODE_POST;
00056     if (n == 0)
00057       return;
00058 
00059     if ((xoff < 2) && (yoff < 2) && (xoff == yoff)) {
00060       if (vbd(ipl) == IPL_DOM) {
00061         DomInfo<IntView,NoOffset<IntView> >* di =
00062           static_cast<Space&>(home).
00063             alloc<DomInfo<IntView,NoOffset<IntView> > >(2*(n+xoff));
00064         for (int i=0; i<n; i++) {
00065           di[xoff+i    ].init(x[i],n+xoff);
00066           di[2*xoff+i+n].init(y[i],n+xoff);
00067         }
00068         if (xoff == 1) {
00069           IntVar x0(home,0,0);
00070           di[0].init(x0, n+xoff);
00071           IntVar y0(home,0,0);
00072           di[n+xoff].init(y0, n+xoff);
00073         }
00074         NoOffset<IntView> noff;
00075         if (same(x,y)) {
00076           GECODE_ES_FAIL((Dom<IntView,NoOffset<IntView>,true>
00077             ::post(home,n+xoff,di,noff,noff)));
00078         } else {
00079           GECODE_ES_FAIL((Dom<IntView,NoOffset<IntView>,false>
00080             ::post(home,n+xoff,di,noff,noff)));
00081         }
00082       } else {
00083         ValInfo<IntView>* vi =
00084           static_cast<Space&>(home).alloc<ValInfo<IntView> >(2*(n+xoff));
00085         for (int i=0; i<n; i++) {
00086           vi[xoff+i    ].init(x[i],n+xoff);
00087           vi[2*xoff+i+n].init(y[i],n+xoff);
00088         }
00089         if (xoff == 1) {
00090           IntVar x0(home,0,0);
00091           vi[0].init(x0, n+xoff);
00092           IntVar y0(home,0,0);
00093           vi[n+xoff].init(y0, n+xoff);
00094         }
00095         NoOffset<IntView> noff;
00096         if (same(x,y)) {
00097           GECODE_ES_FAIL((Val<IntView,NoOffset<IntView>,true>
00098             ::post(home,n+xoff,vi,noff,noff)));
00099         } else {
00100           GECODE_ES_FAIL((Val<IntView,NoOffset<IntView>,false>
00101             ::post(home,n+xoff,vi,noff,noff)));
00102         }
00103       }
00104     } else {
00105       if (vbd(ipl) == IPL_DOM) {
00106         DomInfo<IntView,Offset>* di =
00107           static_cast<Space&>(home).alloc<DomInfo<IntView,Offset> >(2*n);
00108         for (int i=0; i<n; i++) {
00109           di[i  ].init(x[i],n);
00110           di[i+n].init(y[i],n);
00111         }
00112         Offset ox(-xoff);
00113         Offset oy(-yoff);
00114         if (same(x,y)) {
00115           GECODE_ES_FAIL((Dom<IntView,Offset,true>
00116                           ::post(home,n,di,ox,oy)));
00117         } else {
00118           GECODE_ES_FAIL((Dom<IntView,Offset,false>
00119                           ::post(home,n,di,ox,oy)));
00120         }
00121       } else {
00122         ValInfo<IntView>* vi =
00123           static_cast<Space&>(home).alloc<ValInfo<IntView> >(2*n);
00124         for (int i=0; i<n; i++) {
00125           vi[i  ].init(x[i],n);
00126           vi[i+n].init(y[i],n);
00127         }
00128         Offset ox(-xoff);
00129         Offset oy(-yoff);
00130         if (same(x,y)) {
00131           GECODE_ES_FAIL((Val<IntView,Offset,true>
00132                           ::post(home,n,vi,ox,oy)));
00133         } else {
00134           GECODE_ES_FAIL((Val<IntView,Offset,false>
00135                           ::post(home,n,vi,ox,oy)));
00136         }
00137       }
00138     }
00139 
00140   }
00141 
00142   void
00143   channel(Home home, const IntVarArgs& x, const IntVarArgs& y,
00144           IntPropLevel ipl) {
00145     channel(home, x, 0, y, 0, ipl);
00146   }
00147   void
00148   channel(Home home, BoolVar x0, IntVar x1, IntPropLevel) {
00149     using namespace Int;
00150     GECODE_POST;
00151     GECODE_ES_FAIL(Channel::LinkSingle::post(home,x0,x1));
00152   }
00153 
00154   void
00155   channel(Home home, const BoolVarArgs& x, IntVar y, int o,
00156           IntPropLevel) {
00157     using namespace Int;
00158     if (same(x))
00159       throw ArgumentSame("Int::channel");
00160     Limits::check(o,"Int::channel");
00161     GECODE_POST;
00162     ViewArray<BoolView> xv(home,x);
00163     GECODE_ES_FAIL(Channel::LinkMulti::post(home,xv,y,o));
00164   }
00165 
00166 }
00167 
00168 // STATISTICS: int-post