Generated on Tue Apr 18 10:22:00 2017 for Gecode by doxygen 1.6.3

task.hh

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, 2009
00008  *
00009  *  Last modified:
00010  *     $Date: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
00011  *     $Revision: 15137 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #ifndef __GECODE_INT_TASK_HH__
00039 #define __GECODE_INT_TASK_HH__
00040 
00041 #include <gecode/int.hh>
00042 
00043 namespace Gecode { namespace Int {
00044 
00046   template<class ManTask>
00047   class ManToOptTask : public ManTask {
00048   protected:
00050     Int::BoolView _m;
00051   public:
00053 
00054 
00055     ManToOptTask(void);
00057 
00059 
00060 
00061     bool mandatory(void) const;
00063     bool excluded(void) const;
00065     bool optional(void) const;
00067 
00069 
00070     bool assigned(void) const;
00072 
00074 
00075 
00076     ModEvent mandatory(Space& home);
00078     ModEvent excluded(Space& home);
00080 
00082 
00083 
00084     void update(Space& home, bool share, ManToOptTask& t);
00086 
00088 
00089 
00090     void subscribe(Space& home, Propagator& p, PropCond pc);
00092     void cancel(Space& home, Propagator& p, PropCond pc);
00094     void reschedule(Space& home, Propagator& p, PropCond pc);
00096   };
00097 
00098 }}
00099 
00100 #include <gecode/int/task/man-to-opt.hpp>
00101 
00102 namespace Gecode { namespace Int {
00103 
00105   template<class TaskView>
00106   class FwdToBwd : public TaskView {
00107   public:
00109 
00110 
00111     int est(void) const;
00113     int ect(void) const;
00115     int lst(void) const;
00117     int lct(void) const;
00119     int pmin(void) const;
00121     int pmax(void) const;
00123 
00125 
00126 
00127     ModEvent est(Space& home, int n);
00129     ModEvent ect(Space& home, int n);
00131     ModEvent lst(Space& home, int n);
00133     ModEvent lct(Space& home, int n);
00135     ModEvent norun(Space& home, int e, int l);
00137   };
00138 
00139 }}
00140 
00141 #include <gecode/int/task/fwd-to-bwd.hpp>
00142 
00143 namespace Gecode { namespace Int {
00144 
00151   template<class TaskView>
00152   class TaskViewTraits {};
00153 
00160   template<class Task>
00161   class TaskTraits {};
00162 
00163 }}
00164 
00165 namespace Gecode { namespace Int {
00166 
00168   template<class Task>
00169   class TaskArray {
00170   private:
00172     int n;
00174     Task* t;
00175   public:
00177 
00178 
00179     TaskArray(void);
00181     TaskArray(Space& home, int n);
00183     TaskArray(const TaskArray<Task>& a);
00185     const TaskArray<Task>& operator =(const TaskArray<Task>& a);
00187 
00189 
00190 
00191     int size(void) const;
00193     void size(int n);
00195 
00197 
00198 
00199     Task& operator [](int i);
00201     const Task& operator [](int i) const;
00203 
00205 
00206 
00207     void subscribe(Space& home, Propagator& p, PropCond pc=Int::PC_INT_BND);
00209     void cancel(Space& home, Propagator& p, PropCond pc=Int::PC_INT_BND);
00211     void reschedule(Space& home, Propagator& p, PropCond pc=Int::PC_INT_BND);
00213 
00215 
00216 
00217     void update(Space&, bool share, TaskArray& a);
00219 
00220   private:
00221     static void* operator new(size_t);
00222     static void  operator delete(void*,size_t);
00223   };
00224 
00229   template<class Char, class Traits, class Task>
00230   std::basic_ostream<Char,Traits>&
00231   operator <<(std::basic_ostream<Char,Traits>& os,
00232               const TaskArray<Task>& t);
00233 
00234 
00236   template<class TaskView>
00237   class TaskViewArray {
00238   protected:
00240     typedef typename TaskViewTraits<TaskView>::Task Task;
00242     TaskArray<Task>& t;
00243   public:
00245 
00246 
00247     TaskViewArray(TaskArray<Task>& t);
00249 
00251 
00252 
00253     int size(void) const;
00255     void size(int n);
00257 
00259 
00260 
00261     TaskView& operator [](int i);
00263     const TaskView& operator [](int i) const;
00265   private:
00266     static void* operator new(size_t);
00267     static void  operator delete(void*,size_t);
00268   };
00269 
00274   template<class Char, class Traits, class TaskView>
00275   std::basic_ostream<Char,Traits>&
00276   operator <<(std::basic_ostream<Char,Traits>& os,
00277               const TaskViewArray<TaskView>& t);
00278 
00279 }}
00280 
00281 #include <gecode/int/task/array.hpp>
00282 
00283 namespace Gecode { namespace Int {
00284 
00286   enum SortTaskOrder {
00287     STO_EST, 
00288     STO_ECT, 
00289     STO_LST, 
00290     STO_LCT  
00291   };
00292 
00294   template<class TaskView, SortTaskOrder sto, bool inc>
00295   void sort(TaskViewArray<TaskView>& t);
00296 
00298   template<class TaskView, SortTaskOrder sto, bool inc>
00299   void sort(int* map, const TaskViewArray<TaskView>& t);
00300 
00302   template<class TaskView, SortTaskOrder sto, bool inc>
00303   void sort(int* map, int n, const TaskViewArray<TaskView>& t);
00304 
00305 }}
00306 
00307 #include <gecode/int/task/sort.hpp>
00308 
00309 namespace Gecode { namespace Int {
00310 
00312   template<class TaskView, SortTaskOrder sto, bool inc>
00313   class TaskViewIter {
00314   protected:
00316     int* map;
00318     int i;
00320     TaskViewIter(void);
00321   public:
00323     TaskViewIter(Region& r, const TaskViewArray<TaskView>& t);
00325 
00326 
00327     bool operator ()(void) const;
00329     int left(void) const;
00331     void operator ++(void);
00333 
00335 
00336 
00337     int task(void) const;
00339   };
00340 
00342   template<class OptTaskView, SortTaskOrder sto, bool inc>
00343   class ManTaskViewIter : public TaskViewIter<OptTaskView,sto,inc> {
00344   protected:
00345     using TaskViewIter<OptTaskView,sto,inc>::map;
00346     using TaskViewIter<OptTaskView,sto,inc>::i;
00347   public:
00349     ManTaskViewIter(Region& r, const TaskViewArray<OptTaskView>& t);
00350   };
00351 
00352 }}
00353 
00354 #include <gecode/int/task/iter.hpp>
00355 
00356 namespace Gecode { namespace Int {
00357 
00359   int plus(int x, int y);
00360 
00362   long long int plus(long long int x, long long int y);
00363 
00365   double plus(double x, double y);
00366 
00368   template<class TaskView, class Node>
00369   class TaskTree {
00370     template<class,class> friend class TaskTree;
00371   protected:
00373     const TaskViewArray<TaskView>& tasks;
00375     Node* node;
00377     int* _leaf;
00378 
00380     int n_inner(void) const;
00382     int n_nodes(void) const;
00384     static bool n_root(int i);
00386     bool n_leaf(int i) const;
00388     static int n_left(int i);
00390     static bool left(int i);
00392     static int n_right(int i);
00394     static bool right(int i);
00396     static int n_parent(int i);
00397   protected:
00399     Node& leaf(int i);
00401     const Node& root(void) const;
00403     void update(int i, bool l=true);
00405     void init(void);
00407     void update(void);
00409     TaskTree(Region& r, const TaskViewArray<TaskView>& t);
00411     template<class Node2> TaskTree(Region& r,
00412                                    const TaskTree<TaskView,Node2>& t);
00413   };
00414 
00415 }}
00416 
00417 #include <gecode/int/task/tree.hpp>
00418 
00419 namespace Gecode { namespace Int {
00420 
00427   template<class Task, class PL>
00428   class TaskProp : public Propagator {
00429   protected:
00431     TaskArray<Task> t;
00433     TaskProp(Home home, TaskArray<Task>& t);
00435     TaskProp(Space& home, bool shared, TaskProp<Task,PL>& p);
00436   public:
00438     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00440     virtual void reschedule(Space& home);
00442     virtual size_t dispose(Space& home);
00443   };
00444 
00446   template<class OptTask, class PL>
00447   ExecStatus purge(Space& home, Propagator& p, TaskArray<OptTask>& t);
00448 
00450   template<class OptTask, class PL, class Cap>
00451   ExecStatus purge(Space& home, Propagator& p, TaskArray<OptTask>& t, Cap c);
00452 
00454   class PLB {
00455   public:
00457     static const bool basic = true;
00459     static const bool advanced = false;
00461     static const PropCond pc = PC_INT_DOM;
00462   };
00463 
00465   class PLA {
00466   public:
00468     static const bool basic = false;
00470     static const bool advanced = true;
00472     static const PropCond pc = PC_INT_BND;
00473   };
00474 
00476   class PLBA {
00477   public:
00479     static const bool basic = true;
00481     static const bool advanced = true;
00483     static const PropCond pc = PC_INT_DOM;
00484   };
00485 
00486 }}
00487 
00488 #include <gecode/int/task/prop.hpp>
00489 #include <gecode/int/task/purge.hpp>
00490 
00491 namespace Gecode { namespace Int {
00492 
00494   class Event {
00495   public:
00497     enum Type {
00498       LRT = 0, 
00499       LCT = 1, 
00500       EST = 2, 
00501       ZRO = 3, 
00502       ERT = 4, 
00503       END = 5  
00504     };
00505   protected:
00507     unsigned int ei;
00509     int t;
00510   public:
00512     void init(Type e, int t, int i);
00514     Type type(void) const;
00516     int time(void) const;
00518     int idx(void) const;
00520     bool operator <(const Event& e) const;
00522     template<class Task>
00523     static Event* events(Region& r, const TaskArray<Task>& t, bool& assigned);
00525     template<class Task>
00526     static Event* events(Region& r, const TaskArray<Task>& t);
00527   };
00528 
00530   template<class Char, class Traits>
00531   std::basic_ostream<Char,Traits>&
00532   operator <<(std::basic_ostream<Char,Traits>& os, const Event& e);
00533 
00534 }}
00535 
00536 #include <gecode/int/task/event.hpp>
00537 
00538 #endif
00539 
00540 // STATISTICS: int-prop