Generated on Tue Jul 27 2010 21:59:17 for Gecode by doxygen 1.7.1

cumulative.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/cumulative.hh>
00039 
00040 #include <algorithm>
00041 
00042 namespace Gecode {
00043 
00044   void
00045   cumulative(Home home, int c, const TaskTypeArgs& t,
00046              const IntVarArgs& s, const IntArgs& p, const IntArgs& u) {
00047     using namespace Gecode::Scheduling;
00048     using namespace Gecode::Scheduling::Cumulative;
00049     if ((s.size() != p.size()) || (s.size() != u.size()) ||
00050         (s.size() != t.size()))
00051       throw Int::ArgumentSizeMismatch("Scheduling::cumulative");
00052     double w = 0.0;
00053     for (int i=p.size(); i--; ) {
00054       Int::Limits::nonnegative(p[i],"Scheduling::cumulative");
00055       Int::Limits::nonnegative(u[i],"Scheduling::cumulative");
00056       Int::Limits::check(static_cast<double>(s[i].max()) + p[i],
00057                          "Scheduling::cumulative");
00058       Int::Limits::double_check(static_cast<double>(p[i]) * u[i],
00059                                 "Scheduling::cumulative");
00060       w += s[i].width();
00061     }
00062     Int::Limits::double_check(c * w * s.size(),
00063                               "Scheduling::cumulative");
00064     if (home.failed()) return;
00065     bool fixp = true;
00066     for (int i=t.size(); i--;)
00067       if (t[i] != TT_FIXP) {
00068         fixp = false; break;
00069       }
00070     if (fixp) {
00071       TaskArray<ManFixPTask> tasks(home,s.size());
00072       for (int i=0; i<s.size(); i++)
00073         tasks[i].init(s[i],p[i],u[i]);
00074       GECODE_ES_FAIL(ManProp<ManFixPTask>::post(home,c,tasks));
00075     } else {
00076       TaskArray<ManFixPSETask> tasks(home,s.size());
00077       for (int i=s.size(); i--;)
00078         tasks[i].init(t[i],s[i],p[i],u[i]);
00079       GECODE_ES_FAIL(ManProp<ManFixPSETask>::post(home,c,tasks));
00080     }
00081   }
00082 
00083   void
00084   cumulative(Home home, int c, const TaskTypeArgs& t,
00085              const IntVarArgs& s, const IntArgs& p, const IntArgs& u,
00086              const BoolVarArgs& m) {
00087     using namespace Gecode::Scheduling;
00088     using namespace Gecode::Scheduling::Cumulative;
00089     if ((s.size() != p.size()) || (s.size() != u.size()) ||
00090         (s.size() != t.size()) || (s.size() != m.size()))
00091       throw Int::ArgumentSizeMismatch("Scheduling::cumulative");
00092     double w = 0.0;
00093     for (int i=p.size(); i--; ) {
00094       Int::Limits::nonnegative(p[i],"Scheduling::cumulative");
00095       Int::Limits::nonnegative(u[i],"Scheduling::cumulative");
00096       Int::Limits::check(static_cast<double>(s[i].max()) + p[i],
00097                          "Scheduling::cumulative");
00098       Int::Limits::double_check(static_cast<double>(p[i]) * u[i],
00099                                 "Scheduling::cumulative");
00100       w += s[i].width();
00101     }
00102     Int::Limits::double_check(c * w * s.size(),
00103                               "Scheduling::cumulative");
00104     if (home.failed()) return;
00105     bool fixp = true;
00106     for (int i=t.size(); i--;)
00107       if (t[i] != TT_FIXP) {
00108         fixp = false; break;
00109       }
00110     if (fixp) {
00111       TaskArray<OptFixPTask> tasks(home,s.size());
00112       for (int i=0; i<s.size(); i++)
00113         tasks[i].init(s[i],p[i],u[i],m[i]);
00114       GECODE_ES_FAIL(OptProp<OptFixPTask>::post(home,c,tasks));
00115     } else {
00116       TaskArray<OptFixPSETask> tasks(home,s.size());
00117       for (int i=s.size(); i--;)
00118         tasks[i].init(t[i],s[i],p[i],u[i],m[i]);
00119       GECODE_ES_FAIL(OptProp<OptFixPSETask>::post(home,c,tasks));
00120     }
00121   }
00122   void
00123   cumulative(Home home, int c, const IntVarArgs& s, 
00124              const IntArgs& p, const IntArgs& u) {
00125     using namespace Gecode::Scheduling;
00126     using namespace Gecode::Scheduling::Cumulative;
00127     if ((s.size() != p.size()) || (s.size() != u.size()))
00128       throw Int::ArgumentSizeMismatch("Scheduling::cumulative");
00129     double w = 0.0;
00130     for (int i=p.size(); i--; ) {
00131       Int::Limits::nonnegative(p[i],"Scheduling::cumulative");
00132       Int::Limits::nonnegative(u[i],"Scheduling::cumulative");
00133       Int::Limits::check(static_cast<double>(s[i].max()) + p[i],
00134                          "Scheduling::cumulative");
00135       Int::Limits::double_check(static_cast<double>(p[i]) * u[i],
00136                                 "Scheduling::cumulative");
00137       w += s[i].width();
00138     }
00139     Int::Limits::double_check(c * w * s.size(),
00140                               "Scheduling::cumulative");
00141     if (home.failed()) return;
00142     TaskArray<ManFixPTask> t(home,s.size());
00143     for (int i=0; i<s.size(); i++) {
00144       t[i].init(s[i],p[i],u[i]);
00145     }
00146     GECODE_ES_FAIL(ManProp<ManFixPTask>::post(home,c,t));
00147   }
00148 
00149   void
00150   cumulative(Home home, int c, const IntVarArgs& s, const IntArgs& p, 
00151              const IntArgs& u, const BoolVarArgs& m) {
00152     using namespace Gecode::Scheduling;
00153     using namespace Gecode::Scheduling::Cumulative;
00154     if ((s.size() != p.size()) || (s.size() != u.size()) ||
00155         (s.size() != m.size()))
00156       throw Int::ArgumentSizeMismatch("Scheduling::cumulative");
00157     double w = 0.0;
00158     for (int i=p.size(); i--; ) {
00159       Int::Limits::nonnegative(p[i],"Scheduling::cumulative");
00160       Int::Limits::nonnegative(u[i],"Scheduling::cumulative");
00161       Int::Limits::check(static_cast<double>(s[i].max()) + p[i],
00162                          "Scheduling::cumulative");
00163       Int::Limits::double_check(static_cast<double>(p[i]) * u[i],
00164                                 "Scheduling::cumulative");
00165       w += s[i].width();
00166     }
00167     Int::Limits::double_check(c * w * s.size(),
00168                               "Scheduling::cumulative");
00169     if (home.failed()) return;
00170     TaskArray<OptFixPTask> t(home,s.size());
00171     for (int i=0; i<s.size(); i++) {
00172       t[i].init(s[i],p[i],u[i],m[i]);
00173     }
00174     GECODE_ES_FAIL(OptProp<OptFixPTask>::post(home,c,t));
00175   }
00176 
00177   void
00178   cumulative(Home home, int c, const IntVarArgs& s, 
00179              const IntVarArgs& p, const IntVarArgs& e,
00180              const IntArgs& u) {
00181     using namespace Gecode::Scheduling;
00182     using namespace Gecode::Scheduling::Cumulative;
00183     if ((s.size() != p.size()) || (s.size() != e.size()) ||
00184         (s.size() != u.size()))
00185       throw Int::ArgumentSizeMismatch("Scheduling::cumulative");
00186     double w = 0.0;
00187     for (int i=p.size(); i--; ) {
00188       rel(home, p[i], IRT_GQ, 0);
00189     }
00190     for (int i=p.size(); i--; ) {
00191       Int::Limits::nonnegative(u[i],"Scheduling::cumulative");
00192       Int::Limits::check(static_cast<double>(s[i].max()) + p[i].max(),
00193                          "Scheduling::cumulative");
00194       Int::Limits::double_check(static_cast<double>(p[i].max()) * u[i],
00195                                 "Scheduling::cumulative");
00196       w += s[i].width();
00197     }
00198     Int::Limits::double_check(c * w * s.size(),
00199                               "Scheduling::cumulative");
00200     if (home.failed()) return;
00201     TaskArray<ManFlexTask> t(home,s.size());
00202     for (int i=s.size(); i--; )
00203       t[i].init(s[i],p[i],e[i],u[i]);
00204     GECODE_ES_FAIL(ManProp<ManFlexTask>::post(home,c,t));
00205   }
00206 
00207   void
00208   cumulative(Home home, int c, const IntVarArgs& s, const IntVarArgs& p,
00209              const IntVarArgs& e, const IntArgs& u, const BoolVarArgs& m) {
00210     using namespace Gecode::Scheduling;
00211     using namespace Gecode::Scheduling::Cumulative;
00212     if ((s.size() != p.size()) || (s.size() != u.size()) ||
00213         (s.size() != e.size()) || (s.size() != m.size()))
00214       throw Int::ArgumentSizeMismatch("Scheduling::cumulative");
00215     for (int i=p.size(); i--; ) {
00216       rel(home, p[i], IRT_GQ, 0);
00217     }
00218     double w = 0.0;
00219     for (int i=p.size(); i--; ) {
00220       Int::Limits::nonnegative(u[i],"Scheduling::cumulative");
00221       Int::Limits::check(static_cast<double>(s[i].max()) + p[i].max(),
00222                          "Scheduling::cumulative");
00223       Int::Limits::double_check(static_cast<double>(p[i].max()) * u[i],
00224                                 "Scheduling::cumulative");
00225       w += s[i].width();
00226     }
00227     Int::Limits::double_check(c * w * s.size(),
00228                               "Scheduling::cumulative");
00229     if (home.failed()) return;
00230     TaskArray<OptFlexTask> t(home,s.size());
00231     for (int i=s.size(); i--; )
00232       t[i].init(s[i],p[i],e[i],u[i],m[i]);
00233     GECODE_ES_FAIL(OptProp<OptFlexTask>::post(home,c,t));
00234   }
00235   
00236 }
00237 
00238 // STATISTICS: scheduling-post