1 /** 2 * Copyright (c) 2008 Olivier ROUSSEL (olivier.roussel <at> cril.univ-artois.fr) 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a copy 5 * of this software and associated documentation files (the "Software"), to deal 6 * in the Software without restriction, including without limitation the rights 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 * copies of the Software, and to permit persons to whom the Software is 9 * furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 * THE SOFTWARE. 21 */ 22 package org.sat4j.csp.main; 23 import org.sat4j.csp.xml.ICSPCallback; 24 25 public class SimpleCallback implements ICSPCallback { 26 27 /** 28 * signal the beginning of parsing 29 * 30 * @param name 31 * name of the instance 32 */ 33 public void beginInstance(String name) { 34 System.out.println("begin instance : " + name); 35 } 36 37 /** ***************************************************************** */ 38 39 /** 40 * callback called at the beginning of the domains declarations 41 * 42 * @param nbDomains 43 * number of domains that will be declared 44 */ 45 public void beginDomainsSection(int nbDomains) { 46 System.out.println("begin domain section - number of domains : " 47 + nbDomains); 48 } 49 50 /** 51 * callback called at the beginning of the declaration of one domain 52 * 53 * @param name 54 * identifier of the domain 55 * @param nbValue 56 * number of values in the domain 57 */ 58 public void beginDomain(String name, int nbValue) { 59 System.out.println("begin domain : " + name + " - number of values : " 60 + nbValue); 61 } 62 63 /** 64 * add a single value to the current domain 65 * 66 * @param v 67 * value to add to the domain 68 */ 69 public void addDomainValue(int v) { 70 //System.out.println("value : " + v); 71 } 72 73 /** 74 * add the range of values [first..last] to the current domain 75 * 76 * @param first 77 * first value to add to the domain 78 * @param last 79 * last value to add to the domain 80 */ 81 public void addDomainValue(int first, int last) { 82 //System.out.println("values between " + first + " and " + last); 83 } 84 85 /** 86 * ends the definition of the current domain 87 */ 88 public void endDomain() { 89 System.out.println("end domain"); 90 } 91 92 /** 93 * end the definition of all domains 94 */ 95 public void endDomainsSection() { 96 System.out.println("end domain section"); 97 } 98 99 /** ***************************************************************** */ 100 101 /** 102 * callback called at the beginning of the variables declarations 103 * 104 * @param nbVariables 105 * number of variables that will be declared 106 */ 107 public void beginVariablesSection(int nbVariables) { 108 System.out.println("begin variables section - number of variables : " 109 + nbVariables); 110 } 111 112 /** 113 * callback called to define a new variable 114 * 115 * @param name 116 * identifier of the variable 117 * @param domain 118 * identifier of the variable domain 119 */ 120 public void addVariable(String name, String domain) { 121 //System.out.println("variable - name : " + name + " - domain :" + domain); 122 } 123 124 /** 125 * end the definition of all variables 126 */ 127 public void endVariablesSection() { 128 System.out.println("end variables section"); 129 } 130 131 /** ***************************************************************** */ 132 133 /** 134 * callback called at the beginning of the relations declarations 135 * 136 * @param nbRelations 137 * number of relations that will be declared 138 */ 139 public void beginRelationsSection(int nbRelations) { 140 System.out.println("begin relations section - number of relations : " 141 + nbRelations); 142 } 143 144 /** 145 * callback called at the beginning of the declaration of one relation 146 * 147 * @param name 148 * identifier of the relation 149 * @param arity 150 * arity of the relation 151 * @param nbTuples 152 * number of tuples in the relation 153 * @param isSupport 154 * true if tuples represent support, false if tuples represent 155 * conflicts 156 */ 157 public void beginRelation(String name, int arity, int nbTuples, 158 boolean isSupport) { 159 // System.out.println("relation - name : " + name + " - arity : " + arity 160 // + " - number of tuples : " + nbTuples 161 // + (isSupport ? " - support" : " - conflict")); 162 } 163 164 /** 165 * add a single tuple to the current relation 166 * 167 * @param tuple 168 * tuple to add to the relation (contains arity elements) 169 */ 170 public void addRelationTuple(int tuple[]) { 171 // System.out.print("tuple : "); 172 // for (int i : tuple) 173 // System.out.print(i+" "); 174 // System.out.println(); 175 } 176 177 /** 178 * ends the definition of the current relation 179 */ 180 public void endRelation() { 181 // System.out.println("end relation"); 182 } 183 184 /** 185 * end the definition of all relations 186 */ 187 public void endRelationsSection() { 188 System.out.println("end relations section"); 189 } 190 191 /** ***************************************************************** */ 192 193 /** 194 * callback called at the beginning of the predicates declarations 195 * 196 * @param nbPredicates 197 * number of predicates that will be declared 198 */ 199 public void beginPredicatesSection(int nbPredicates) { 200 System.out.println("begin predicates section - number of predicates : " 201 + nbPredicates); 202 } 203 204 /** 205 * callback called at the beginning of the declaration of one predicate 206 * 207 * @param name 208 * identifier of the predicate 209 */ 210 public void beginPredicate(String name) { 211 System.out.println("predicate - name : " + name); 212 } 213 214 /** 215 * add a formal parameter to the current predicate 216 * 217 * @param name 218 * name of the parameter 219 * @param type 220 * type of the parameter 221 */ 222 public void addFormalParameter(String name, String type) { 223 System.out.println("parameter - name : " + name + " - type : " + type); 224 } 225 226 /** 227 * provide the expression of the current predicate 228 * 229 * @param expression 230 * the abstract syntax tree representing the expression 231 */ 232 public void predicateExpression(String expression) { 233 System.out.println("predicate expression : " + expression); 234 } 235 236 /** 237 * ends the definition of the current predicate 238 */ 239 public void endPredicate() { 240 System.out.println("end predicate"); 241 } 242 243 /** 244 * end the definition of all predicates 245 */ 246 public void endPredicatesSection() { 247 System.out.println("end predicates section"); 248 } 249 250 /** ***************************************************************** */ 251 252 /** 253 * callback called at the beginning of the constraints declarations 254 * 255 * @param nbConstraints 256 * number of constraints that will be declared 257 */ 258 public void beginConstraintsSection(int nbConstraints) { 259 System.out 260 .println("begin constraints section - number of constraints : " 261 + nbConstraints); 262 } 263 264 /** 265 * callback called at the beginning of the declaration of one constraint 266 * 267 * @param name 268 * identifier of the constraint 269 * @param arity 270 * arity of the constraint 271 */ 272 public void beginConstraint(String name, int arity) { 273 System.out 274 .println("constraint - name : " + name + " - arity : " + arity); 275 } 276 277 /** 278 * provide the definition of the current constraint 279 * 280 * @param name 281 * the refererence to the definition of this constraint. May be a 282 * relation, a predicate or the name of a global constraint 283 */ 284 public void constraintReference(String name) { 285 System.out.println("reference :" + name); 286 } 287 288 /** 289 * declares that a variable is in the constraint scope 290 * 291 * @param name 292 * name of the variable 293 */ 294 public void addVariableToConstraint(String name) { 295 System.out.println("var : " + name); 296 } 297 298 /** 299 * add an effective parameter which is a simple variable to the current 300 * constraint 301 * 302 * @param name 303 * name of the variable passed as parameter 304 */ 305 public void addEffectiveParameter(String name) { 306 System.out.println("param : " + name); 307 } 308 309 /** 310 * add an effective parameter which is a simple variable to the current 311 * constraint 312 * 313 * @param value 314 * name of the variable passed as parameter 315 */ 316 public void addEffectiveParameter(int value) { 317 System.out.println("param : " + value); 318 } 319 320 /** 321 * provide the expression of the current constraint as an expression in a 322 * syntac chosen by the solver 323 * 324 * @param expr 325 * the expression 326 */ 327 public void constraintExpression(String expr) { 328 System.out.println("contraint expression : " + expr); 329 } 330 331 /** 332 * ends the definition of the current constraint 333 */ 334 public void endConstraint() { 335 System.out.println("end constraint"); 336 } 337 338 /** 339 * end the definition of all constraints 340 */ 341 public void endConstraintsSection() { 342 System.out.println("end constraints section"); 343 } 344 345 /** 346 * begins the list tag for parameters of a constraint 347 */ 348 public void beginParameterList(){} 349 350 /** 351 * provides an integer value in a parameter list of a constraint 352 * @param value 353 * value of current list item 354 */ 355 public void addIntegerItem(int value){} 356 357 /** 358 * provides the name of a variable in a parameter list of a constraint 359 * @param name 360 * name of the current list item 361 */ 362 public void addVariableItem(String name){} 363 364 /** 365 * ends the list tag for parameters of a constraint 366 */ 367 public void endParamaterList(){} 368 369 /** 370 * provides a constant value 371 */ 372 public void addConstantParameter(String name, int value){} 373 374 375 376 /** ***************************************************************** */ 377 378 /** 379 * signal the end of parsing 380 */ 381 public void endInstance() { 382 System.out.println("end instance"); 383 } 384 385 }