this repo has no description
at develop 3.8 kB view raw
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * 6 * Copyright: 7 * Christian Schulte, 2016 8 * 9 * This file is part of Gecode, the generic constraint 10 * development environment: 11 * http://www.gecode.org 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining 14 * a copy of this software and associated documentation files (the 15 * "Software"), to deal in the Software without restriction, including 16 * without limitation the rights to use, copy, modify, merge, publish, 17 * distribute, sublicense, and/or sell copies of the Software, and to 18 * permit persons to whom the Software is furnished to do so, subject to 19 * the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be 22 * included in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 * 32 */ 33 34namespace Gecode { namespace Int { 35 36 /// Duplicate of an integer view 37 class IntTraceView { 38 protected: 39 /// Ranges capturing the variable domain 40 RangeList* dom; 41 public: 42 /// Default constructor (initializes with no view) 43 IntTraceView(void); 44 /// Duplicate view \a y 45 IntTraceView(Space& home, IntView y); 46 /// Give access to ranges 47 RangeList* ranges(void) const; 48 /// Update duplicated view from view \a y and modification delta \a d 49 void prune(Space& home, IntView y, const Delta& d); 50 /// Update during cloning 51 void update(Space& home, IntTraceView x); 52 /// Return slack measure 53 static unsigned long long int slack(IntView x); 54 }; 55 56 forceinline 57 IntTraceView::IntTraceView(void) {} 58 59 forceinline 60 IntTraceView::IntTraceView(Space& home, IntView y) { 61 ViewRanges<IntView> yr(y); 62 RangeList::copy(home, dom, yr); 63 } 64 65 forceinline RangeList* 66 IntTraceView::ranges(void) const { 67 return dom; 68 } 69 70 forceinline void 71 IntTraceView::prune(Space& home, IntView y, const Delta& d) { 72 if (y.range() && (dom->next() == nullptr)) { 73 dom->min(y.min()); dom->max(y.max()); 74 } else if (!y.any(d) && (y.max(d)+1 == y.min())) { 75 // The lower bound has been adjusted 76 if (y.min() > dom->max()) { 77 RangeList* p = dom; 78 RangeList* l = p->next(); 79 while ((l != nullptr) && (l->max() < y.min())) { 80 p=l; l=l->next(); 81 } 82 dom->dispose(home,p); 83 dom = l; 84 } 85 dom->min(y.min()); 86 } else if (!y.any(d) && (y.max()+1 == y.min(d))) { 87 // upper bound has been adjusted 88 if ((y.max() <= dom->max()) && (dom->next() == nullptr)) { 89 dom->max(y.max()); 90 } else { 91 RangeList* p = dom; 92 RangeList* l = p->next(); 93 while ((l != nullptr) && (l->min() <= y.max())) { 94 p=l; l=l->next(); 95 } 96 p->max(y.max()); 97 if (p->next() != nullptr) 98 p->next()->dispose(home); 99 p->next(nullptr); 100 } 101 } else { 102 // Just copy the domain 103 ViewRanges<IntView> yr(y); 104 RangeList::overwrite(home,dom,yr); 105 } 106 } 107 108 forceinline void 109 IntTraceView::update(Space& home, IntTraceView y) { 110 Iter::Ranges::RangeList yr(y.dom); 111 RangeList::copy(home,dom,yr); 112 } 113 114 forceinline unsigned long long int 115 IntTraceView::slack(IntView x) { 116 return x.width()-1; 117 } 118 119 120}} 121 122// STATISTICS: int-trace