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

event.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, 2015
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 namespace Gecode { namespace Int {
00035 
00036   forceinline void
00037   Event::init(Event::Type e0, int t0, int i0) {
00038     ei=static_cast<unsigned int>(e0 | (i0 << 3)); t=t0;
00039   }
00040 
00041   forceinline Event::Type
00042   Event::type(void) const {
00043     return static_cast<Type>(ei & 7);
00044   }
00045   forceinline int
00046   Event::time(void) const {
00047     return t;
00048   }
00049   forceinline int
00050   Event::idx(void) const {
00051     return static_cast<int>(ei >> 3);;
00052   }
00053 
00054   forceinline bool
00055   Event::operator <(const Event& e) const {
00056     if (time() == e.time())
00057       return type() < e.type();
00058     return time() < e.time();
00059   }
00060 
00061 
00062   template<class Char, class Traits>
00063   inline std::basic_ostream<Char,Traits>&
00064   operator <<(std::basic_ostream<Char,Traits>& os, const Event& e) {
00065     std::basic_ostringstream<Char,Traits> s;
00066     s.copyfmt(os); s.width(0);
00067     s << '[';
00068     switch (e.type()) {
00069     case Event::LRT: s << "LRT"; break;
00070     case Event::LCT: s << "LCT"; break;
00071     case Event::EST: s << "EST"; break;
00072     case Event::ZRO: s << "ZRO"; break;
00073     case Event::ERT: s << "ERT"; break;
00074     default: GECODE_NEVER;
00075     }
00076     s << ',' << e.time() << ',' << e.idx() << ']';
00077     return os << s.str();
00078   }
00079 
00080 
00081   template<class Task>
00082   forceinline Event*
00083   Event::events(Region& r, const TaskArray<Task>& t, bool& assigned) {
00084     Event* e = r.alloc<Event>(4*t.size()+1);
00085 
00086     // Initialize events
00087     assigned=true;
00088     bool required=false;
00089 
00090     int n=0;
00091     for (int i=0; i<t.size(); i++)
00092       if (t[i].assigned()) {
00093         // Only add required part
00094         if (t[i].pmin() > 0) {
00095           required = true;
00096           e[n++].init(Event::ERT,t[i].lst(),i);
00097           e[n++].init(Event::LRT,t[i].ect(),i);
00098         } else if (t[i].pmax() == 0) {
00099           required = true;
00100           e[n++].init(Event::ZRO,t[i].lst(),i);
00101         }
00102       } else {
00103         assigned = false;
00104         e[n++].init(Event::EST,t[i].est(),i);
00105         e[n++].init(Event::LCT,t[i].lct(),i);
00106         // Check whether task has required part
00107         if (t[i].lst() < t[i].ect()) {
00108           required = true;
00109           e[n++].init(Event::ERT,t[i].lst(),i);
00110           e[n++].init(Event::LRT,t[i].ect(),i);
00111         }
00112       }
00113 
00114     if (!required)
00115       return NULL;
00116 
00117     // Sort events
00118     Support::quicksort(e, n);
00119 
00120     // Write end marker
00121     e[n++].init(Event::END,Limits::infinity,0);
00122 
00123     return e;
00124   }
00125 
00126   template<class Task>
00127   forceinline Event*
00128   Event::events(Region& r, const TaskArray<Task>& t) {
00129     Event* e = r.alloc<Event>(2*t.size()+1);
00130 
00131     // Only add assigned and mandatory tasks
00132     int n=0;
00133     for (int i=0; i<t.size(); i++)
00134       if (t[i].assigned() && t[i].mandatory()) {
00135         if (t[i].pmin() > 0) {
00136           e[n++].init(Event::ERT,t[i].lst(),i);
00137           e[n++].init(Event::LRT,t[i].ect(),i);
00138         } else if (t[i].pmax() == 0) {
00139           e[n++].init(Event::ZRO,t[i].lst(),i);
00140         }
00141       } else {
00142         assert(!t[i].excluded());
00143         return NULL;
00144       }
00145 
00146     // Sort events
00147     Support::quicksort(e, n);
00148 
00149     // Write end marker
00150     e[n++].init(Event::END,Limits::infinity,0);
00151 
00152     return e;
00153   }
00154 
00155 }}
00156 
00157 // STATISTICS: int-prop