/Users/jamian/Desktop/gecode-2.0.1/contribs/qecode/NaiveValueHeuristics.cc

Go to the documentation of this file.
00001 /*********************************************************[naivevalueheuristics.cc]
00002 Copyright (c) 2007, Universite d'Orleans - Jeremie Vautard, Marco Benedetti,
00003 Arnaud Lallouet.
00004 
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011 
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 THE SOFTWARE.
00022 *****************************************************************************/
00023 
00024 
00025 #include "NaiveValueHeuristics.hh"
00026 
00027 int** SmallestValueFirst::subSet(Implicative* home,int var,int* nbRanges) {
00028     switch (home->type_of_v[var]) {
00029         case VTYPE_INT : {
00030             int zeValue = getIntVar(home,whichSpaceOwns(home,var),var)->min();
00031             *nbRanges = 1;
00032             int** ret = new int*[2];
00033             ret[0]=new int[1];
00034             ret[1]=new int[1];
00035             ret[0][0]=zeValue;
00036             ret[1][0]=zeValue;
00037             return ret;
00038         }
00039             break;
00040         case VTYPE_BOOL : {
00041             int zeValue = getBoolVar(home,whichSpaceOwns(home,var),var)->min();
00042             *nbRanges = 1;
00043             int** ret = new int*[2];
00044             ret[0]=new int[1];
00045             ret[1]=new int[1];
00046             ret[0][0]=zeValue;
00047             ret[1][0]=zeValue;
00048             return ret;
00049         }
00050             break;    
00051     }
00052     return 0;
00053 }
00054 
00055 
00056 int** LargestValueFirst::subSet(Implicative* home,int var,int* nbRanges) {
00057     switch (home->type_of_v[var]) {
00058         case VTYPE_INT : {
00059             int zeValue = getIntVar(home,whichSpaceOwns(home,var),var)->max();
00060             *nbRanges = 1;
00061             int** ret = new int*[2];
00062             ret[0]=new int[1];
00063             ret[1]=new int[1];
00064             ret[0][0]=zeValue;
00065             ret[1][0]=zeValue;
00066             return ret;
00067         }
00068             break;
00069         case VTYPE_BOOL : {
00070             int zeValue = getBoolVar(home,whichSpaceOwns(home,var),var)->max();
00071             *nbRanges = 1;
00072             int** ret = new int*[2];
00073             ret[0]=new int[1];
00074             ret[1]=new int[1];
00075             ret[0][0]=zeValue;
00076             ret[1][0]=zeValue;
00077             return ret;
00078         }
00079             break;
00080     }
00081     return 0;
00082 }
00083 
00084 int** MedianValueFirst::subSet(Implicative* home,int var,int* nbRanges) {
00085     switch (home->type_of_v[var]) {
00086         case VTYPE_INT : {
00087             int zeValue = getIntVar(home,whichSpaceOwns(home,var),var)->med();
00088             *nbRanges = 1;
00089             int** ret = new int*[2];
00090             ret[0]=new int[1];
00091             ret[1]=new int[1];
00092             ret[0][0]=zeValue;
00093             ret[1][0]=zeValue;
00094             return ret;
00095         }
00096             break;
00097         case VTYPE_BOOL : {
00098             int zeValue = getBoolVar(home,whichSpaceOwns(home,var),var)->med();
00099             *nbRanges = 1;
00100             int** ret = new int*[2];
00101             ret[0]=new int[1];
00102             ret[1]=new int[1];
00103             ret[0][0]=zeValue;
00104             ret[1][0]=zeValue;
00105             return ret;
00106         }
00107             break;
00108     }
00109     return 0;
00110 }
00111 
00112 int** SmallestHalfFirst::subSet(Implicative* home,int var,int* nbRanges) {
00113     switch (home->type_of_v[var]) {
00114         case VTYPE_INT : {
00115             int zeMin = getIntVar(home,whichSpaceOwns(home,var),var)->min();
00116             int zeMax = getIntVar(home,whichSpaceOwns(home,var),var)->med();
00117             int varMax = getIntVar(home,whichSpaceOwns(home,var),var)->max();
00118             if (zeMax == varMax) zeMax--;
00119             *nbRanges = 1;
00120             int** ret = new int*[2];
00121             ret[0]=new int[1];
00122             ret[1]=new int[1];
00123             ret[0][0]=zeMin;
00124             ret[1][0]=zeMax;
00125             return ret;
00126         }
00127             break;
00128         case VTYPE_BOOL : {
00129             int zeValue = getBoolVar(home,whichSpaceOwns(home,var),var)->min();
00130             *nbRanges = 1;
00131             int** ret = new int*[2];
00132             ret[0]=new int[1];
00133             ret[1]=new int[1];
00134             ret[0][0]=zeValue;
00135             ret[1][0]=zeValue;
00136             return ret;
00137         }
00138             break;
00139     }
00140     return 0;
00141 }
00142 
00143 int** LargestHalfFirst::subSet(Implicative* home,int var,int* nbRanges) {
00144     switch (home->type_of_v[var]) {
00145         case VTYPE_INT : {
00146             int zeMin = getIntVar(home,whichSpaceOwns(home,var),var)->med();
00147             int zeMax = getIntVar(home,whichSpaceOwns(home,var),var)->max();
00148             int varMin = getIntVar(home,whichSpaceOwns(home,var),var)->min();
00149             if (zeMin == varMin) zeMin++;
00150             *nbRanges = 1;
00151             int** ret = new int*[2];
00152             ret[0]=new int[1];
00153             ret[1]=new int[1];
00154             ret[0][0]=zeMin;
00155             ret[1][0]=zeMax;
00156             return ret;
00157         }
00158             break;
00159         case VTYPE_BOOL : {
00160             int zeValue = getBoolVar(home,whichSpaceOwns(home,var),var)->max();
00161             *nbRanges = 1;
00162             int** ret = new int*[2];
00163             ret[0]=new int[1];
00164             ret[1]=new int[1];
00165             ret[0][0]=zeValue;
00166             ret[1][0]=zeValue;
00167             return ret;
00168         }
00169             break;
00170     }
00171     return 0;
00172 }

Generated on Thu Feb 7 14:33:45 2008 for qecode by  doxygen 1.5.2