Generated on Fri May 13 2011 22:41:21 for Gecode by doxygen 1.7.1

unary.cpp

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, 2009
00009  *     Guido Tack, 2010
00010  *
00011  *  Last modified:
00012  *     $Date: 2011-01-18 23:37:08 +0100 (Tue, 18 Jan 2011) $ by $Author: tack $
00013  *     $Revision: 11551 $
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 #include <gecode/scheduling/unary.hh>
00041 
00042 #include <algorithm>
00043 
00044 namespace Gecode {
00045 
00046   void
00047   unary(Home home, const IntVarArgs& s, const IntArgs& p) {
00048     using namespace Gecode::Scheduling;
00049     using namespace Gecode::Scheduling::Unary;
00050     if (s.same(home))
00051       throw Int::ArgumentSame("Scheduling::unary");
00052     if (s.size() != p.size())
00053       throw Int::ArgumentSizeMismatch("Scheduling::unary");
00054     for (int i=p.size(); i--; ) {
00055       Int::Limits::nonnegative(p[i],"Scheduling::unary");
00056       Int::Limits::check(static_cast<double>(s[i].max()) + p[i],
00057                          "Scheduling::unary");
00058     }
00059     if (home.failed()) return;
00060     TaskArray<ManFixPTask> t(home,s.size());
00061     for (int i=s.size(); i--; )
00062       t[i].init(s[i],p[i]);
00063     GECODE_ES_FAIL(ManProp<ManFixPTask>::post(home,t));
00064   }
00065 
00066   void
00067   unary(Home home, const TaskTypeArgs& t,
00068         const IntVarArgs& s, const IntArgs& p) {
00069     using namespace Gecode::Scheduling;
00070     using namespace Gecode::Scheduling::Unary;
00071     if ((s.size() != p.size()) || (s.size() != t.size()))
00072       throw Int::ArgumentSizeMismatch("Scheduling::unary");
00073     for (int i=p.size(); i--; ) {
00074       if (t[i] == TT_FIXP)
00075         Int::Limits::nonnegative(p[i],"Scheduling::unary");
00076       else
00077         Int::Limits::check(p[i],"Scheduling::unary");
00078       Int::Limits::check(static_cast<double>(s[i].max()) + p[i],
00079                          "Scheduling::unary");
00080     }
00081     if (home.failed()) return;
00082     bool fixp = true;
00083     for (int i=t.size(); i--;)
00084       if (t[i] != TT_FIXP) {
00085         fixp = false; break;
00086       }
00087     if (fixp) {
00088       TaskArray<ManFixPTask> tasks(home,s.size());
00089       for (int i=s.size(); i--; )
00090         tasks[i].init(s[i],p[i]);
00091       GECODE_ES_FAIL(ManProp<ManFixPTask>::post(home,tasks));
00092     } else {
00093       TaskArray<ManFixPSETask> tasks(home,s.size());
00094       for (int i=s.size(); i--;)
00095         tasks[i].init(t[i],s[i],p[i]);
00096       GECODE_ES_FAIL(ManProp<ManFixPSETask>::post(home,tasks));
00097     }
00098   }
00099 
00100   void
00101   unary(Home home, const IntVarArgs& s, const IntArgs& p, 
00102         const BoolVarArgs& m) {
00103     using namespace Gecode::Scheduling;
00104     using namespace Gecode::Scheduling::Unary;
00105     if (s.same(home))
00106       throw Int::ArgumentSame("Scheduling::unary");
00107     if ((s.size() != p.size()) || (s.size() != m.size()))
00108       throw Int::ArgumentSizeMismatch("Scheduling::unary");
00109     for (int i=p.size(); i--; ) {
00110       Int::Limits::nonnegative(p[i],"Scheduling::unary");
00111       Int::Limits::check(static_cast<double>(s[i].max()) + p[i],
00112                          "Scheduling::unary");
00113     }
00114     if (home.failed()) return;
00115     TaskArray<OptFixPTask> t(home,s.size());
00116     for (int i=s.size(); i--; )
00117       t[i].init(s[i],p[i],m[i]);
00118     GECODE_ES_FAIL(OptProp<OptFixPTask>::post(home,t));
00119   }
00120 
00121   void
00122   unary(Home home, const TaskTypeArgs& t,
00123         const IntVarArgs& s, const IntArgs& p, const BoolVarArgs& m) {
00124     using namespace Gecode::Scheduling;
00125     using namespace Gecode::Scheduling::Unary;
00126     if ((s.size() != p.size()) || (s.size() != t.size()) ||
00127         (s.size() != m.size()))
00128       throw Int::ArgumentSizeMismatch("Scheduling::unary");
00129     for (int i=p.size(); i--; ) {
00130       if (t[i] == TT_FIXP)
00131         Int::Limits::nonnegative(p[i],"Scheduling::unary");
00132       else
00133         Int::Limits::check(p[i],"Scheduling::unary");
00134       Int::Limits::check(static_cast<double>(s[i].max()) + p[i],
00135                          "Scheduling::unary");
00136     }
00137     if (home.failed()) return;
00138     bool fixp = true;
00139     for (int i=t.size(); i--;)
00140       if (t[i] != TT_FIXP) {
00141         fixp = false; break;
00142       }
00143     if (fixp) {
00144       TaskArray<OptFixPTask> tasks(home,s.size());
00145       for (int i=s.size(); i--; )
00146         tasks[i].init(s[i],p[i],m[i]);
00147       GECODE_ES_FAIL(OptProp<OptFixPTask>::post(home,tasks));
00148     } else {
00149       TaskArray<OptFixPSETask> tasks(home,s.size());
00150       for (int i=s.size(); i--;)
00151         tasks[i].init(t[i],s[i],p[i],m[i]);
00152       GECODE_ES_FAIL(OptProp<OptFixPSETask>::post(home,tasks));
00153     }
00154   }
00155 
00156   void
00157   unary(Home home, const IntVarArgs& s, const IntVarArgs& p,
00158         const IntVarArgs& e) {
00159     using namespace Gecode::Scheduling;
00160     using namespace Gecode::Scheduling::Unary;
00161     if ((s.size() != p.size()) || (s.size() != e.size()))
00162       throw Int::ArgumentSizeMismatch("Scheduling::unary");
00163     if (home.failed()) return;
00164     for (int i=p.size(); i--; ) {
00165       rel(home, p[i], IRT_GQ, 0);
00166     }
00167     TaskArray<ManFlexTask> t(home,s.size());
00168     for (int i=s.size(); i--; )
00169       t[i].init(s[i],p[i],e[i]);
00170     GECODE_ES_FAIL(ManProp<ManFlexTask>::post(home,t));
00171   }
00172 
00173   void
00174   unary(Home home, const IntVarArgs& s, const IntVarArgs& p, 
00175         const IntVarArgs& e, const BoolVarArgs& m) {
00176     using namespace Gecode::Scheduling;
00177     using namespace Gecode::Scheduling::Unary;
00178     if ((s.size() != p.size()) || (s.size() != m.size()) ||
00179         (s.size() != e.size()))
00180       throw Int::ArgumentSizeMismatch("Scheduling::unary");
00181     if (home.failed()) return;
00182     for (int i=p.size(); i--; ) {
00183       rel(home, p[i], IRT_GQ, 0);
00184     }
00185     TaskArray<OptFlexTask> t(home,s.size());
00186     for (int i=s.size(); i--; )
00187       t[i].init(s[i],p[i],e[i],m[i]);
00188     GECODE_ES_FAIL(OptProp<OptFlexTask>::post(home,t));
00189   }
00190 
00191 }
00192 
00193 // STATISTICS: scheduling-post