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