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