Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
6.5 kB · 230 lines
C++
at develop
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- *//* * Main authors: * Christian Schulte <schulte@gecode.org> * Guido Tack <tack@gecode.org> * * 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 TaskView, bool inc> class StoEst { public: /// Sort order bool operator ()(const TaskView& t1, const TaskView& t2) const; };
/// Sort by earliest completion times template<class TaskView, bool inc> class StoEct { public: /// Sort order bool operator ()(const TaskView& t1, const TaskView& t2) const; };
/// Sort by latest start times template<class TaskView, bool inc> class StoLst { public: /// Sort order bool operator ()(const TaskView& t1, const TaskView& t2) const; };
/// Sort by latest completion times template<class TaskView, bool inc> class StoLct { public: /// Sort order bool operator ()(const TaskView& t1, const TaskView& t2) const; };
/// Sorting maps rather than tasks template<class TaskView, template<class,bool> class STO, bool inc> class SortMap { private: /// The tasks const TaskViewArray<TaskView>& tasks; /// The sorting order for tasks STO<TaskView,inc> sto; public: /// Initialize SortMap(const TaskViewArray<TaskView>& t); /// Sort order bool operator ()(int& i, int& j) const; };
template<class TaskView, bool inc> forceinline bool StoEst<TaskView,inc>::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<class TaskView, bool inc> forceinline bool StoEct<TaskView,inc>::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<class TaskView, bool inc> forceinline bool StoLst<TaskView,inc>::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<class TaskView, bool inc> forceinline bool StoLct<TaskView,inc>::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 TaskView, template<class,bool> class STO, bool inc> forceinline SortMap<TaskView,STO,inc>::SortMap(const TaskViewArray<TaskView>& t) : tasks(t) {} template<class TaskView, template<class,bool> class STO, bool inc> forceinline bool SortMap<TaskView,STO,inc>::operator ()(int& i, int& j) const { return sto(tasks[i],tasks[j]); }
template<class TaskView, SortTaskOrder sto, bool inc> forceinline void sort(TaskViewArray<TaskView>& t) { switch (sto) { case STO_EST: { StoEst<TaskView,inc> o; Support::quicksort(&t[0], t.size(), o); } break; case STO_ECT: { StoEct<TaskView,inc> o; Support::quicksort(&t[0], t.size(), o); } break; case STO_LST: { StoLst<TaskView,inc> o; Support::quicksort(&t[0], t.size(), o); } break; case STO_LCT: { StoLct<TaskView,inc> o; Support::quicksort(&t[0], t.size(), o); } break; default: GECODE_NEVER; } }
template<class TaskView, SortTaskOrder sto, bool inc> forceinline void sort(int* map, const TaskViewArray<TaskView>& t) { for (int i=0; i<t.size(); i++) map[i]=i; switch (sto) { case STO_EST: { SortMap<TaskView,StoEst,inc> o(t); Support::quicksort(map, t.size(), o); } break; case STO_ECT: { SortMap<TaskView,StoEct,inc> o(t); Support::quicksort(map, t.size(), o); } break; case STO_LST: { SortMap<TaskView,StoLst,inc> o(t); Support::quicksort(map, t.size(), o); } break; case STO_LCT: { SortMap<TaskView,StoLct,inc> o(t); Support::quicksort(map, t.size(), o); } break; default: GECODE_NEVER; } }
template<class TaskView, SortTaskOrder sto, bool inc> forceinline void sort(int* map, int n, const TaskViewArray<TaskView>& t) { switch (sto) { case STO_EST: { SortMap<TaskView,StoEst,inc> o(t); Support::quicksort(map, n, o); } break; case STO_ECT: { SortMap<TaskView,StoEct,inc> o(t); Support::quicksort(map, n, o); } break; case STO_LST: { SortMap<TaskView,StoLst,inc> o(t); Support::quicksort(map, n, o); } break; case STO_LCT: { SortMap<TaskView,StoLct,inc> o(t); Support::quicksort(map, n, o); } break; default: GECODE_NEVER; } }
}}
// STATISTICS: int-other