Generated on Tue Apr 18 10:21:51 2017 for Gecode by doxygen 1.6.3

time-tabling.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  *     Guido Tack <tack@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2015
00009  *     Guido Tack, 2010
00010  *
00011  *  Last modified:
00012  *     $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
00013  *     $Revision: 14967 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 namespace Gecode { namespace Int { namespace Unary {
00041 
00042   template<class Task>
00043   ExecStatus
00044   timetabling(Space& home, Propagator& p, TaskArray<Task>& t) {
00045     Region r(home);
00046 
00047     bool assigned;
00048     if (Event* e = Event::events(r,t,assigned)) {
00049       // Whether resource is free
00050       bool free = true;
00051       // Set of current but not required tasks
00052       Support::BitSet<Region> tasks(r,static_cast<unsigned int>(t.size()));
00053 
00054       // Process events
00055       do {
00056         // Current time
00057         int time = e->time();
00058 
00059         // Process events for completion of required part
00060         for ( ; (e->type() == Event::LRT) && (e->time() == time); e++)
00061           if (t[e->idx()].mandatory()) {
00062             tasks.set(static_cast<unsigned int>(e->idx()));
00063             free = true;
00064           }
00065 
00066         // Process events for completion of task
00067         for ( ; (e->type() == Event::LCT) && (e->time() == time); e++)
00068           tasks.clear(static_cast<unsigned int>(e->idx()));
00069 
00070         // Process events for start of task
00071         for ( ; (e->type() == Event::EST) && (e->time() == time); e++)
00072           tasks.set(static_cast<unsigned int>(e->idx()));
00073 
00074         // Process events for zero-length task
00075         for ( ; (e->type() == Event::ZRO) && (e->time() == time); e++)
00076           if (!free)
00077             return ES_FAILED;
00078 
00079         // Norun start time
00080         int nrstime = time;
00081         // Process events for start of required part
00082         for ( ; (e->type() == Event::ERT) && (e->time() == time); e++)
00083           if (t[e->idx()].mandatory()) {
00084             tasks.clear(static_cast<unsigned int>(e->idx()));
00085             if (!free)
00086               return ES_FAILED;
00087             free = false;
00088             nrstime = time+1;
00089           } else if (t[e->idx()].optional() && !free) {
00090             GECODE_ME_CHECK(t[e->idx()].excluded(home));
00091           }
00092 
00093         if (!free)
00094           for (Iter::Values::BitSet<Support::BitSet<Region> > j(tasks);
00095                j(); ++j)
00096             // Task j cannot run from time to next time - 1
00097             if (t[j.val()].mandatory())
00098               GECODE_ME_CHECK(t[j.val()].norun(home, nrstime, e->time() - 1));
00099 
00100       } while (e->type() != Event::END);
00101     }
00102 
00103     if (assigned)
00104       return home.ES_SUBSUMED(p);
00105 
00106     return ES_NOFIX;
00107   }
00108 
00109 }}}
00110 
00111 // STATISTICS: int-prop