Generated on Tue Apr 18 10:22:00 2017 for Gecode by doxygen 1.6.3

int-trace-view.hpp

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  *
00006  *  Copyright:
00007  *     Christian Schulte, 2016
00008  *
00009  *  Last modified:
00010  *     $Date: 2017-03-17 23:04:57 +0100 (Fri, 17 Mar 2017) $ by $Author: schulte $
00011  *     $Revision: 15597 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 namespace Gecode { namespace Int {
00039 
00041   class IntTraceView {
00042   protected:
00044     RangeList* dom;
00045   public:
00047     IntTraceView(void);
00049     IntTraceView(Space& home, IntView y);
00051     RangeList* ranges(void) const;
00053     void prune(Space& home, IntView y, const Delta& d);
00055     void update(Space& home, bool share, IntTraceView x);
00057     static unsigned long long int slack(IntView x);
00058   };
00059 
00060   forceinline
00061   IntTraceView::IntTraceView(void) {}
00062 
00063   forceinline
00064   IntTraceView::IntTraceView(Space& home, IntView y) {
00065     ViewRanges<IntView> yr(y);
00066     RangeList::copy(home, dom, yr);
00067   }
00068 
00069   forceinline RangeList*
00070   IntTraceView::ranges(void) const {
00071     return dom;
00072   }
00073 
00074   forceinline void
00075   IntTraceView::prune(Space& home, IntView y, const Delta& d) {
00076     if (y.range() && (dom->next() == NULL)) {
00077       dom->min(y.min()); dom->max(y.max());
00078     } else if (!y.any(d) && (y.max(d)+1 == y.min())) {
00079       // The lower bound has been adjusted
00080       if (y.min() > dom->max()) {
00081         RangeList* p = dom;
00082         RangeList* l = p->next();
00083         while ((l != NULL) && (l->max() < y.min())) {
00084           p=l; l=l->next();
00085         }
00086         dom->dispose(home,p);
00087         dom = l;
00088       }
00089       dom->min(y.min());
00090     } else if (!y.any(d) && (y.max()+1 == y.min(d))) {
00091       // upper bound has been adjusted
00092       if ((y.max() <= dom->max()) && (dom->next() == NULL)) {
00093         dom->max(y.max());
00094       } else {
00095         RangeList* p = dom;
00096         RangeList* l = p->next();
00097         while ((l != NULL) && (l->min() <= y.max())) {
00098           p=l; l=l->next();
00099         }
00100         p->max(y.max());
00101         if (p->next() != NULL)
00102           p->next()->dispose(home);
00103         p->next(NULL);
00104       }
00105     } else {
00106       // Just copy the domain
00107       ViewRanges<IntView> yr(y);
00108       RangeList::overwrite(home,dom,yr);
00109     }
00110   }
00111 
00112   forceinline void
00113   IntTraceView::update(Space& home, bool, IntTraceView y) {
00114     Iter::Ranges::RangeList yr(y.dom);
00115     RangeList::copy(home,dom,yr);
00116   }
00117 
00118   forceinline unsigned long long int
00119   IntTraceView::slack(IntView x) {
00120     return x.width()-1;
00121   }
00122 
00123 
00124 }}
00125 
00126 // STATISTICS: int-trace