@@ -894,7 +894,173 @@ namespace Test { namespace Int {
894894 }
895895 };
896896
897+ // / %Test for Boolean argument maximum constraint
898+ class ArgMaxBool : public Test {
899+ protected:
900+ // / Offset to be used
901+ int offset;
902+ // / Whether to use tie-breaking
903+ bool tiebreak;
904+ public:
905+ // / Create and register test
906+ ArgMaxBool (int n, int o, bool tb)
907+ : Test(" Arithmetic::ArgMaxBool::" +str(o)+" ::" +str(tb)+" ::" +str(n),
908+ n+1 ,0 ,n+1 ,
909+ false ,tb ? Gecode::IPL_DEF : Gecode::IPL_DOM),
910+ offset (o), tiebreak(tb) {}
911+ // / %Test whether \a x is solution
912+ virtual bool solution (const Assignment& x) const {
913+ int n=x.size ()-1 ;
914+ if ((x[n] < offset) || (x[n] >= n + offset))
915+ return false ;
916+ int m=x[0 ]; int p=0 ;
917+ if (x[0 ] > 1 )
918+ return false ;
919+ for (int i=1 ; i<n; i++) {
920+ if (x[i] > 1 )
921+ return false ;
922+ if (x[i] > m) {
923+ p=i; m=x[i];
924+ }
925+ }
926+ return tiebreak ? (p + offset == x[n]) : (m == x[x[n]-offset]);
927+ }
928+ // / Post constraint on \a x
929+ virtual void post (Gecode::Space& home, Gecode::IntVarArray& x) {
930+ int n=x.size ()-1 ;
931+ Gecode::BoolVarArgs m (n);
932+ for (int i=0 ; i<n; i++)
933+ m[i]=channel (home,x[i]);
934+ Gecode::argmax (home, m, offset, x[n], tiebreak);
935+ }
936+ };
937+
938+ // / %Test for argument maximum constraint with shared variables
939+ class ArgMaxBoolShared : public Test {
940+ protected:
941+ // / Whether to use tie-breaking
942+ bool tiebreak;
943+ public:
944+ // / Create and register test
945+ ArgMaxBoolShared (int n, bool tb)
946+ : Test(" Arithmetic::ArgMaxBool::Shared::" +str(tb)+" ::" +str(n),n+1 ,0 ,n+1 ,
947+ false ),
948+ tiebreak (tb) {
949+ testfix=false ;
950+ }
951+ // / %Test whether \a x is solution
952+ virtual bool solution (const Assignment& x) const {
953+ int n=x.size ()-1 ;
954+ if ((x[n] < 0 ) || (x[n] >= 2 *n))
955+ return false ;
956+ Gecode::IntArgs y (2 *n);
957+ for (int i=0 ; i<n; i++)
958+ y[2 *i+0 ]=y[2 *i+1 ]=x[i];
959+ int m=y[0 ]; int p=0 ;
960+ if (y[0 ] > 1 )
961+ return false ;
962+ for (int i=1 ; i<2 *n; i++) {
963+ if (y[i] > 1 )
964+ return false ;
965+ if (y[i] > m) {
966+ p=i; m=y[i];
967+ }
968+ }
969+ return tiebreak ? (p == x[n]) : (m == y[x[n]]);
970+ }
971+ // / Post constraint on \a x
972+ virtual void post (Gecode::Space& home, Gecode::IntVarArray& x) {
973+ int n=x.size ()-1 ;
974+ Gecode::BoolVarArgs m (2 *n);
975+ for (int i=0 ; i<n; i++)
976+ m[2 *i+0 ]=m[2 *i+1 ]=channel (home,x[i]);
977+ Gecode::argmax (home, m, x[n], tiebreak);
978+ }
979+ };
980+
981+ // / %Test for argument minimum constraint
982+ class ArgMinBool : public Test {
983+ protected:
984+ // / Which offset to use
985+ int offset;
986+ // / Whether to use tie-breaking
987+ bool tiebreak;
988+ public:
989+ // / Create and register test
990+ ArgMinBool (int n, int o, bool tb)
991+ : Test(" Arithmetic::ArgMinBool::" +str(o)+" ::" +str(tb)+" ::" +str(n),
992+ n+1 ,0 ,n+1 ,
993+ false ,tb ? Gecode::IPL_DEF : Gecode::IPL_DOM),
994+ offset (o), tiebreak(tb) {}
995+ // / %Test whether \a x is solution
996+ virtual bool solution (const Assignment& x) const {
997+ int n=x.size ()-1 ;
998+ if ((x[n] < offset) || (x[n] >= n + offset))
999+ return false ;
1000+ int m=x[0 ]; int p=0 ;
1001+ if (x[0 ] < 0 || x[0 ] > 1 )
1002+ return false ;
1003+ for (int i=1 ; i<n; i++) {
1004+ if (x[i] < 0 || x[i] > 1 )
1005+ return false ;
1006+ if (x[i] < m) {
1007+ p=i; m=x[i];
1008+ }
1009+ }
1010+ return tiebreak ? (p+offset == x[n]) : (m == x[x[n]-offset]);
1011+ }
1012+ // / Post constraint on \a x
1013+ virtual void post (Gecode::Space& home, Gecode::IntVarArray& x) {
1014+ int n=x.size ()-1 ;
1015+ Gecode::BoolVarArgs m (n);
1016+ for (int i=0 ; i<n; i++)
1017+ m[i]=channel (home,x[i]);
1018+ Gecode::argmin (home, m, offset, x[n], tiebreak);
1019+ }
1020+ };
8971021
1022+ // / %Test for argument minimum constraint with shared variables
1023+ class ArgMinBoolShared : public Test {
1024+ protected:
1025+ // / Whether to use tie-breaking
1026+ bool tiebreak;
1027+ public:
1028+ // / Create and register test
1029+ ArgMinBoolShared (int n, bool tb)
1030+ : Test(" Arithmetic::ArgMinBool::Shared::" +str(tb)+" ::" +str(n),n+1 ,0 ,n+1 ,
1031+ false ),
1032+ tiebreak (tb) {
1033+ testfix=false ;
1034+ }
1035+ // / %Test whether \a x is solution
1036+ virtual bool solution (const Assignment& x) const {
1037+ int n=x.size ()-1 ;
1038+ if ((x[n] < 0 ) || (x[n] >= 2 *n))
1039+ return false ;
1040+ Gecode::IntArgs y (2 *n);
1041+ for (int i=0 ; i<n; i++)
1042+ y[2 *i+0 ]=y[2 *i+1 ]=x[i];
1043+ int m=y[0 ]; int p=0 ;
1044+ if (y[0 ] > 1 )
1045+ return false ;
1046+ for (int i=1 ; i<2 *n; i++) {
1047+ if (y[i] > 1 )
1048+ return false ;
1049+ if (y[i] < m) {
1050+ p=i; m=y[i];
1051+ }
1052+ }
1053+ return tiebreak ? (p == x[n]) : (m == y[x[n]]);
1054+ }
1055+ // / Post constraint on \a x
1056+ virtual void post (Gecode::Space& home, Gecode::IntVarArray& x) {
1057+ int n=x.size ()-1 ;
1058+ Gecode::BoolVarArgs m (2 *n);
1059+ for (int i=0 ; i<n; i++)
1060+ m[2 *i+0 ]=m[2 *i+1 ]=channel (home,x[i]);
1061+ Gecode::argmin (home, m, x[n], tiebreak);
1062+ }
1063+ };
8981064
8991065 // / Help class to create and register tests
9001066 class Create {
@@ -1069,6 +1235,19 @@ namespace Test { namespace Int {
10691235 (void ) new ArgMin (i,0 ,false );
10701236 (void ) new ArgMin (i,1 ,false );
10711237 (void ) new ArgMinShared (i,false );
1238+
1239+ (void ) new ArgMaxBool (i,0 ,true );
1240+ (void ) new ArgMaxBool (i,1 ,true );
1241+ (void ) new ArgMaxBoolShared (i,true );
1242+ (void ) new ArgMinBool (i,0 ,true );
1243+ (void ) new ArgMinBool (i,1 ,true );
1244+ (void ) new ArgMinBoolShared (i,true );
1245+ (void ) new ArgMaxBool (i,0 ,false );
1246+ (void ) new ArgMaxBool (i,1 ,false );
1247+ (void ) new ArgMaxBoolShared (i,false );
1248+ (void ) new ArgMinBool (i,0 ,false );
1249+ (void ) new ArgMinBool (i,1 ,false );
1250+ (void ) new ArgMinBoolShared (i,false );
10721251 }
10731252 }
10741253 };
0 commit comments