/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Christian Schulte * Guido Tack * * Copyright: * Christian Schulte, 2009 * Guido Tack, 2010 * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ namespace Gecode { namespace Int { /// Sort by earliest start times template class StoEst { public: /// Sort order bool operator ()(const TaskView& t1, const TaskView& t2) const; }; /// Sort by earliest completion times template class StoEct { public: /// Sort order bool operator ()(const TaskView& t1, const TaskView& t2) const; }; /// Sort by latest start times template class StoLst { public: /// Sort order bool operator ()(const TaskView& t1, const TaskView& t2) const; }; /// Sort by latest completion times template class StoLct { public: /// Sort order bool operator ()(const TaskView& t1, const TaskView& t2) const; }; /// Sorting maps rather than tasks template class STO, bool inc> class SortMap { private: /// The tasks const TaskViewArray& tasks; /// The sorting order for tasks STO sto; public: /// Initialize SortMap(const TaskViewArray& t); /// Sort order bool operator ()(int& i, int& j) const; }; template forceinline bool StoEst::operator () (const TaskView& t1, const TaskView& t2) const { return inc ? (t1.est() < t2.est() || (t1.est()==t2.est() && t1.lct() < t2.lct())) : (t2.est() < t1.est() || (t2.est()==t1.est() && t2.lct() < t1.lct())); } template forceinline bool StoEct::operator () (const TaskView& t1, const TaskView& t2) const { return inc ? (t1.ect() < t2.ect() || (t1.ect()==t2.ect() && t1.lst() < t2.lst())) : (t2.ect() < t1.ect() || (t2.ect()==t1.ect() && t2.lst() < t1.lst())); } template forceinline bool StoLst::operator () (const TaskView& t1, const TaskView& t2) const { return inc ? (t1.lst() < t2.lst() || (t1.lst()==t2.lst() && t1.ect() < t2.ect())) : (t2.lst() < t1.lst() || (t2.lst()==t1.lst() && t2.ect() < t1.ect())); } template forceinline bool StoLct::operator () (const TaskView& t1, const TaskView& t2) const { return inc ? (t1.lct() < t2.lct() || (t1.lct()==t2.lct() && t1.est() < t2.est())) : (t2.lct() < t1.lct() || (t2.lct()==t1.lct() && t2.est() < t1.est())); } template class STO, bool inc> forceinline SortMap::SortMap(const TaskViewArray& t) : tasks(t) {} template class STO, bool inc> forceinline bool SortMap::operator ()(int& i, int& j) const { return sto(tasks[i],tasks[j]); } template forceinline void sort(TaskViewArray& t) { switch (sto) { case STO_EST: { StoEst o; Support::quicksort(&t[0], t.size(), o); } break; case STO_ECT: { StoEct o; Support::quicksort(&t[0], t.size(), o); } break; case STO_LST: { StoLst o; Support::quicksort(&t[0], t.size(), o); } break; case STO_LCT: { StoLct o; Support::quicksort(&t[0], t.size(), o); } break; default: GECODE_NEVER; } } template forceinline void sort(int* map, const TaskViewArray& t) { for (int i=0; i o(t); Support::quicksort(map, t.size(), o); } break; case STO_ECT: { SortMap o(t); Support::quicksort(map, t.size(), o); } break; case STO_LST: { SortMap o(t); Support::quicksort(map, t.size(), o); } break; case STO_LCT: { SortMap o(t); Support::quicksort(map, t.size(), o); } break; default: GECODE_NEVER; } } template forceinline void sort(int* map, int n, const TaskViewArray& t) { switch (sto) { case STO_EST: { SortMap o(t); Support::quicksort(map, n, o); } break; case STO_ECT: { SortMap o(t); Support::quicksort(map, n, o); } break; case STO_LST: { SortMap o(t); Support::quicksort(map, n, o); } break; case STO_LCT: { SortMap o(t); Support::quicksort(map, n, o); } break; default: GECODE_NEVER; } } }} // STATISTICS: int-other