Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
14 kB · 538 lines
C++
at develop
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- *//* * Main authors: * Christian Schulte <schulte@gecode.org> * Guido Tack <tack@gecode.org> * * Copyright: * Christian Schulte, 2009 * Guido Tack, 2010 * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */
namespace Gecode { namespace Int { namespace Unary {
/* * Mandatory fixed task */
forceinline ManFixPTask::ManFixPTask(void) {} forceinline ManFixPTask::ManFixPTask(IntVar s, int p) : _s(s), _p(p) {} forceinline void ManFixPTask::init(IntVar s, int p) { _s=s; _p=p; } forceinline void ManFixPTask::init(const ManFixPTask& t) { _s=t._s; _p=t._p; }
forceinline int ManFixPTask::est(void) const { return _s.min(); } forceinline int ManFixPTask::ect(void) const { return _s.min()+_p; } forceinline int ManFixPTask::lst(void) const { return _s.max(); } forceinline int ManFixPTask::lct(void) const { return _s.max()+_p; } forceinline int ManFixPTask::pmin(void) const { return _p; } forceinline int ManFixPTask::pmax(void) const { return _p; } forceinline IntVar ManFixPTask::st(void) const { return _s; }
forceinline bool ManFixPTask::mandatory(void) const { return true; } forceinline bool ManFixPTask::excluded(void) const { return false; } forceinline bool ManFixPTask::optional(void) const { return false; }
forceinline bool ManFixPTask::assigned(void) const { return _s.assigned(); }
forceinline ModEvent ManFixPTask::est(Space& home, int n) { return _s.gq(home,n); } forceinline ModEvent ManFixPTask::ect(Space& home, int n) { return _s.gq(home,n-_p); } forceinline ModEvent ManFixPTask::lst(Space& home, int n) { return _s.lq(home,n); } forceinline ModEvent ManFixPTask::lct(Space& home, int n) { return _s.lq(home,n-_p); } forceinline ModEvent ManFixPTask::norun(Space& home, int e, int l) { if (e <= l) { Iter::Ranges::Singleton r(e-_p+1,l); return _s.minus_r(home,r,false); } else { return ME_INT_NONE; } }
forceinline ModEvent ManFixPTask::mandatory(Space&) { return ME_INT_NONE; } forceinline ModEvent ManFixPTask::excluded(Space&) { return ME_INT_FAILED; }
forceinline void ManFixPTask::update(Space& home, ManFixPTask& t) { _s.update(home,t._s); _p=t._p; }
forceinline void ManFixPTask::subscribe(Space& home, Propagator& p, PropCond pc) { _s.subscribe(home, p, pc); } forceinline void ManFixPTask::cancel(Space& home, Propagator& p, PropCond pc) { _s.cancel(home, p, pc); } forceinline void ManFixPTask::reschedule(Space& home, Propagator& p, PropCond pc) { _s.reschedule(home, p, pc); }
template<class Char, class Traits> std::basic_ostream<Char,Traits>& operator <<(std::basic_ostream<Char,Traits>& os, const ManFixPTask& t) { std::basic_ostringstream<Char,Traits> s; s.copyfmt(os); s.width(0); s << t.est() << ':' << t.pmin() << ':' << t.lct(); return os << s.str(); }
/* * Mandatory fixed task with fixed processing, start or end time */
forceinline ManFixPSETask::ManFixPSETask(void) {} forceinline ManFixPSETask::ManFixPSETask(TaskType t, IntVar s, int p) : ManFixPTask(s,p), _t(t) {} forceinline void ManFixPSETask::init(TaskType t, IntVar s, int p) { ManFixPTask::init(s,p); _t=t; } forceinline void ManFixPSETask::init(const ManFixPSETask& t0) { ManFixPTask::init(t0); _t = t0._t; }
forceinline int ManFixPSETask::est(void) const { return (_t == TT_FIXS) ? _p : _s.min(); } forceinline int ManFixPSETask::ect(void) const { switch (_t) { case TT_FIXP: return _s.min()+_p; case TT_FIXS: return _s.min(); case TT_FIXE: return _p; default: GECODE_NEVER; } return 0; } forceinline int ManFixPSETask::lst(void) const { return (_t == TT_FIXS) ? _p : _s.max(); } forceinline int ManFixPSETask::lct(void) const { switch (_t) { case TT_FIXP: return _s.max()+_p; case TT_FIXS: return _s.max(); case TT_FIXE: return _p; default: GECODE_NEVER; } return 0; } forceinline int ManFixPSETask::pmin(void) const { switch (_t) { case TT_FIXP: return _p; case TT_FIXS: return _s.min()-_p; case TT_FIXE: return _p-_s.max(); default: GECODE_NEVER; } return 0; } forceinline int ManFixPSETask::pmax(void) const { switch (_t) { case TT_FIXP: return _p; case TT_FIXS: return _s.max()-_p; case TT_FIXE: return _p-_s.min(); default: GECODE_NEVER; } return 0; }
forceinline ModEvent ManFixPSETask::est(Space& home, int n) { switch (_t) { case TT_FIXE: // fall through case TT_FIXP: return _s.gq(home,n); case TT_FIXS: return (n <= _p) ? ME_INT_NONE : ME_INT_FAILED; default: GECODE_NEVER; } return ME_INT_NONE; } forceinline ModEvent ManFixPSETask::ect(Space& home, int n) { switch (_t) { case TT_FIXE: return (n <= _p) ? ME_INT_NONE : ME_INT_FAILED; case TT_FIXP: return _s.gq(home,n-_p); case TT_FIXS: return _s.gq(home,n); default: GECODE_NEVER; } return ME_INT_NONE; } forceinline ModEvent ManFixPSETask::lst(Space& home, int n) { switch (_t) { case TT_FIXE: // fall through case TT_FIXP: return _s.lq(home,n); case TT_FIXS: return (n >= _p) ? ME_INT_NONE : ME_INT_FAILED; default: GECODE_NEVER; } return ME_INT_NONE; } forceinline ModEvent ManFixPSETask::lct(Space& home, int n) { switch (_t) { case TT_FIXE: return (n >= _p) ? ME_INT_NONE : ME_INT_FAILED; case TT_FIXP: return _s.lq(home,n-_p); case TT_FIXS: return _s.lq(home,n); default: GECODE_NEVER; } return ME_INT_NONE; } forceinline ModEvent ManFixPSETask::norun(Space& home, int e, int l) { if (e <= l) { switch (_t) { case TT_FIXP: { Iter::Ranges::Singleton r(e-_p+1,l); return _s.minus_r(home,r,false); } case TT_FIXE: if (e <= _p) return _s.gr(home,l); break; case TT_FIXS: if (l >= _p) return _s.lq(home,e); break; default: GECODE_NEVER; } return ME_INT_NONE; } else { return ME_INT_NONE; } }
forceinline void ManFixPSETask::update(Space& home, ManFixPSETask& t) { ManFixPTask::update(home,t); _t=t._t; }
template<class Char, class Traits> std::basic_ostream<Char,Traits>& operator <<(std::basic_ostream<Char,Traits>& os, const ManFixPSETask& t) { std::basic_ostringstream<Char,Traits> s; s.copyfmt(os); s.width(0); s << t.est() << ':' << t.pmin() << ':' << t.lct(); return os << s.str(); }
/* * Mandatory flexible task */
forceinline ManFlexTask::ManFlexTask(void) {} forceinline ManFlexTask::ManFlexTask(IntVar s, IntVar p, IntVar e) : _s(s), _p(p), _e(e) {} forceinline void ManFlexTask::init(IntVar s, IntVar p, IntVar e) { _s=s; _p=p; _e=e; } forceinline void ManFlexTask::init(const ManFlexTask& t) { _s=t._s; _p=t._p; _e=t._e; }
forceinline int ManFlexTask::est(void) const { return _s.min(); } forceinline int ManFlexTask::ect(void) const { return _e.min(); } forceinline int ManFlexTask::lst(void) const { return _s.max(); } forceinline int ManFlexTask::lct(void) const { return _e.max(); } forceinline int ManFlexTask::pmin(void) const { return _p.min(); } forceinline int ManFlexTask::pmax(void) const { return _p.max(); } forceinline IntVar ManFlexTask::st(void) const { return _s; } forceinline IntVar ManFlexTask::p(void) const { return _p; } forceinline IntVar ManFlexTask::e(void) const { return _e; }
forceinline bool ManFlexTask::mandatory(void) const { return true; } forceinline bool ManFlexTask::excluded(void) const { return false; } forceinline bool ManFlexTask::optional(void) const { return false; }
forceinline bool ManFlexTask::assigned(void) const { return _s.assigned() && _p.assigned() && _e.assigned(); }
forceinline ModEvent ManFlexTask::est(Space& home, int n) { return _s.gq(home,n); } forceinline ModEvent ManFlexTask::ect(Space& home, int n) { return _e.gq(home,n); } forceinline ModEvent ManFlexTask::lst(Space& home, int n) { return _s.lq(home,n); } forceinline ModEvent ManFlexTask::lct(Space& home, int n) { return _e.lq(home,n); } forceinline ModEvent ManFlexTask::norun(Space& home, int e, int l) { if (e <= l) { Iter::Ranges::Singleton sr(e-_p.min()+1,l); if (me_failed(_s.minus_r(home,sr,false))) return ME_INT_FAILED; Iter::Ranges::Singleton er(e+1,_p.min()+l); return _e.minus_r(home,er,false); } else { return ME_INT_NONE; } }
forceinline ModEvent ManFlexTask::mandatory(Space&) { return ME_INT_NONE; } forceinline ModEvent ManFlexTask::excluded(Space&) { return ME_INT_FAILED; }
forceinline void ManFlexTask::update(Space& home, ManFlexTask& t) { _s.update(home,t._s); _p.update(home,t._p); _e.update(home,t._e); }
forceinline void ManFlexTask::subscribe(Space& home, Propagator& p, PropCond pc) { _s.subscribe(home, p, pc); _p.subscribe(home, p, pc); _e.subscribe(home, p, pc); } forceinline void ManFlexTask::cancel(Space& home, Propagator& p, PropCond pc) { _s.cancel(home, p, pc); _p.cancel(home, p, pc); _e.cancel(home, p, pc); } forceinline void ManFlexTask::reschedule(Space& home, Propagator& p, PropCond pc) { _s.reschedule(home, p, pc); _p.reschedule(home, p, pc); _e.reschedule(home, p, pc); }
template<class Char, class Traits> std::basic_ostream<Char,Traits>& operator <<(std::basic_ostream<Char,Traits>& os, const ManFlexTask& t) { std::basic_ostringstream<Char,Traits> s; s.copyfmt(os); s.width(0); s << t.est() << ':' << t.lst() << ':' << t.pmin() << ':' << t.pmax() << ':' << t.ect() << ':' << t.lct(); return os << s.str(); }
/* * Optional fixed task */
forceinline OptFixPTask::OptFixPTask(void) {} forceinline OptFixPTask::OptFixPTask(IntVar s, int p, BoolVar m) { ManFixPTask::init(s,p); _m=m; } forceinline void OptFixPTask::init(IntVar s, int p, BoolVar m) { ManFixPTask::init(s,p); _m=m; }
template<class Char, class Traits> std::basic_ostream<Char,Traits>& operator <<(std::basic_ostream<Char,Traits>& os, const OptFixPTask& t) { std::basic_ostringstream<Char,Traits> s; s.copyfmt(os); s.width(0); s << t.est() << ':' << t.pmin() << ':' << t.lct() << ':' << (t.mandatory() ? '1' : (t.optional() ? '?' : '0')); return os << s.str(); }
/* * Optional fixed task */
forceinline OptFixPSETask::OptFixPSETask(void) {} forceinline OptFixPSETask::OptFixPSETask(TaskType t,IntVar s,int p,BoolVar m) { ManFixPSETask::init(t,s,p); _m=m; } forceinline void OptFixPSETask::init(TaskType t, IntVar s, int p, BoolVar m) { ManFixPSETask::init(t,s,p); _m=m; }
template<class Char, class Traits> std::basic_ostream<Char,Traits>& operator <<(std::basic_ostream<Char,Traits>& os, const OptFixPSETask& t) { std::basic_ostringstream<Char,Traits> s; s.copyfmt(os); s.width(0); s << t.est() << ':' << t.pmin() << ':' << t.lct() << ':' << (t.mandatory() ? '1' : (t.optional() ? '?' : '0')); return os << s.str(); }
/* * Optional flexible task */
forceinline OptFlexTask::OptFlexTask(void) {} forceinline OptFlexTask::OptFlexTask(IntVar s, IntVar p, IntVar e, BoolVar m) { ManFlexTask::init(s,p,e); _m=m; } forceinline void OptFlexTask::init(IntVar s, IntVar p, IntVar e, BoolVar m) { ManFlexTask::init(s,p,e); _m=m; }
template<class Char, class Traits> std::basic_ostream<Char,Traits>& operator <<(std::basic_ostream<Char,Traits>& os, const OptFlexTask& t) { std::basic_ostringstream<Char,Traits> s; s.copyfmt(os); s.width(0); s << t.est() << ':' << t.lst() << ':' << t.pmin() << ':' << t.pmax() << ':' << t.ect() << ':' << t.lct() << ':' << (t.mandatory() ? '1' : (t.optional() ? '?' : '0')); return os << s.str(); }
}}}
// STATISTICS: int-var