| 45 | |
| 46 | template<class VA, class VB, bool tiebreak> |
| 47 | ExecStatus |
| 48 | ArgMax<VA,VB,tiebreak>::post(Home home, IdxViewArray<VA>& x, VB y) { |
| 49 | assert(x.size() > 0); |
| 50 | if (x.size() == 1) { |
| 51 | GECODE_ME_CHECK(y.eq(home,x[0].idx)); |
| 52 | } else if (y.assigned()) { |
| 53 | int max=0; |
| 54 | while (x[max].idx < y.val()) |
| 55 | max++; |
| 56 | assert(x[max].idx == y.val()); |
| 57 | if (tiebreak) |
| 58 | for (int i=0; i<max; i++) |
| 59 | GECODE_ES_CHECK((Rel::Le<VA,VA>::post(home, |
| 60 | x[i].view,x[max].view))); |
| 61 | else |
| 62 | for (int i=0; i<max; i++) |
| 63 | GECODE_ES_CHECK((Rel::Lq<VA,VA>::post(home, |
| 64 | x[i].view,x[max].view))); |
| 65 | for (int i=max+1; i<x.size(); i++) |
| 66 | GECODE_ES_CHECK((Rel::Lq<VA,VA>::post(home, |
| 67 | x[i].view,x[max].view))); |
| 68 | } else { |
| 69 | (void) new (home) ArgMax<VA,VB,tiebreak>(home,x,y); |
| 70 | } |
| 71 | return ES_OK; |
| 72 | } |
| 73 | |
| 74 | template<class VA, class VB, bool tiebreak> |
| 75 | forceinline |