/*============================================================================= * parser for CSP instances represented in XCSP3 Format * * Copyright (c) 2015 xcsp.org (contact xcsp.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. *============================================================================= */ #ifndef COSOCO_XCSP3CORECALLBACKS_H #define COSOCO_XCSP3CORECALLBACKS_H #include "XCSP3Constants.h" #include "XCSP3Variable.h" #include "XCSP3Constraint.h" #include "XCSP3Tree.h" #include #include namespace XCSP3Core { using namespace std; class XCSP3CoreCallbacks { protected : vector classesToDiscard; public : /** * If true, the intension constraint are retrieved with an expression (nothing is done in order to help you) * (false by default) * Otherwise, the callback that take a canonized tree of the expression is called */ bool intensionUsingString; /** * If true, the parse recognizes special intensional constraints such as x + k op y and call a specific callback. */ bool recognizeSpecialIntensionCases; /** * If true, the parser recognizes special count constraints: atleast, atmost, exactly, among, exctalyVariable * and call a specific callback */ bool recognizeSpecialCountCases; /** * If true, the parser recognizes special nvalues constraints: AllEqual, NotAllEqual, AllDiff * and call a specific callback */ bool recognizeNValuesCases; /** * if true, sum are normalized: merge same variables, remove variables with coef equal to zero.. */ bool normalizeSum; XCSP3CoreCallbacks() { intensionUsingString = false; recognizeSpecialIntensionCases = true; recognizeSpecialCountCases = true; recognizeNValuesCases = true; normalizeSum = true; } /** * remove specific classes such as symmetryBreaking, clues... * @param cl */ void addClassToDiscard(string cl) { classesToDiscard.push_back(cl); } bool discardedClasses(string classes) { if(classes == "") return false; for(string c : classesToDiscard) if(classes.find(c) != std::string::npos) return true; return false; } // All these callbacks are called when the tag starts and when it ends. // This is not necessary to override them. /** * Start to parse a XCSP instance. * Related to tag * See http://xcsp.org/specifications/skeleton * @param type COP or CSP */ virtual void beginInstance(InstanceType type) {} /** * End of parsing * Related to tag * See http://xcsp.org/specifications/skeleton */ virtual void endInstance() {} /** * Start to parse variables * Related to tag * See http://xcsp.org/specifications/skeleton */ virtual void beginVariables() {} /** * The end of parsing variables * Related to tag * See http://xcsp.org/specifications/skeleton */ virtual void endVariables() {} /** * Start to parse an array of variables * Related to tag * See http://xcsp.org/specifications/arrays * Note that for each variable in the array a call is done to one of the functions #buildVariableInteger * * @param id the id (name) of the array variable */ virtual void beginVariableArray(string id) {} //beginArray /** * End of parsing an array of variables * Related to tag * See http://xcsp.org/specifications/arrays */ virtual void endVariableArray() {} /** * Start to parse constraints * Related to tag * See http://xcsp.org/specifications/skeleton */ virtual void beginConstraints() {} /** * The end of parsing constraints * Related to tag * See http://xcsp.org/specifications/skeleton */ virtual void endConstraints() {} /** * Start to parse a group of constraints * Related to tag * See http://xcsp.org/specifications/groups * Note that for each constraint of the group a call is done to the related callback * * @param id the id (name) of the group */ virtual void beginGroup(string id) {} /** * The end of parsing group of constraints * Related to tag * See http://xcsp.org/specifications/groups */ virtual void endGroup() {} /** * Start to parse a block of constraints * Related to tag * See http://xcsp.org/specifications/blocks * Note that for each constraint of the block a call is done to the related callback * * Note that if you want to discard some blocks, you need to call the function addClassToDiscard with the related class * * @param classes the classes related to the block symmetryBreaking, clues... */ virtual void beginBlock(string classes) {} /** * The end of parsing a block of constraints * Related to tag * See http://xcsp.org/specifications/blocks */ virtual void endBlock() {} /** * Start to parse a slide constraint * Related to tag * See http://xcsp.org/specifications/slide * Note that for each constraint of the block a call is done to the related callback * * @param id the id (name) of the slide * @param circular is the slide circular? */ virtual void beginSlide(string id, bool circular) {} /** * The end of parsing a slide constraint * Related to tag * See http://xcsp.org/specifications/slide */ virtual void endSlide() {} /** * Start to parse objectives * Related to tag * See http://xcsp.org/specifications/objectives */ virtual void beginObjectives() {} /** * The end of parsing objectives * Related to tag * See http://xcsp.org/specifications/objectives */ virtual void endObjectives() {} /** * The start of parsing annotations * Related to tag */ virtual void beginAnnotations() {} /** * The end of parsing annotations * Related to tag */ virtual void endAnnotations() {} //-------------------------------------------------------------------------------------- // Build Variable. Must be implemented. //-------------------------------------------------------------------------------------- /** * The callback function related to an integer variable with a range domain * See http://xcsp.org/specifications/integers * * Example: 0..6 * * @param id the id (name) of the group * @param minValue the minimum value in the range * @param maxValue the maxnimum value in the range */ virtual void buildVariableInteger(string id, int minValue, int maxValue) = 0; /** * The callback function related to an integer variable with a domain consisting in a sequence of integers * See http://xcsp.org/specifications/integers * * Example 1 3 5 10 * * @param id the id (name) of the group * @param values the set of values in the domain */ virtual void buildVariableInteger(string id, vector &values) = 0; /** * All callbacks related to constraints. * Note that the variables related to a constraint are #XVariable instances. A XVariable contains an id and * the related domain. * (see XCSP3Variable.h) * */ //-------------------------------------------------------------------------------------- // Universal Constraints //-------------------------------------------------------------------------------------- /** * The special constraint always true * Nothing to do * @param id * @param list */ virtual void buildConstraintTrue(string id) {} /** * The special constraint always false * The problem is unsatisfiable * @param id * @param list */ virtual void buildConstraintFalse(string id) { std::cout << "c constraint " + id + " is always false (see during parsing)\n"; std::cout << "s UNSATISFIABLE\n"; } //-------------------------------------------------------------------------------------- // Basic constraints //-------------------------------------------------------------------------------------- /** * The callback function related to an constraint in extension * See http://xcsp.org/specifications/extension * * Example: * * y1 y2 y3 y4 * (1,2,3,4)(3,1,3,4) * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param tuples the set of tuples in the constraint * @param support support or conflicts? * @param hasStar is the tuples contain star values? */ virtual void buildConstraintExtension(string id, vector list, vector> &tuples, bool support, bool hasStar) { std::cout << "WARNING: tuples are not checked wrt domains" << std::endl; throw runtime_error("extension constraint is not yet supported"); } /* * The callback function related to an constraint in extension * Note that this callback is related to an unary constraint * See http://xcsp.org/specifications/extension * Example: * * x * 2 6 * * * @param id the id (name) of the constraint * @param variable the variable * @param tuples the set of tuple (here just set of ints) * @param support support or conflicts? * @param hasStar is the tuples contain star values? */ virtual void buildConstraintExtension(string id, XVariable *variable, vector &tuples, bool support, bool hasStar) { throw runtime_error("unary extension constraint is not yet supported"); } /** * The callback function related to a constraint in extension where the set of tuples is exactly the same * than the previous one. * It is the case when a group of constraint contains an extension constraint. * This is useful to save space and share the set of tuples of all constraints. * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param support support or conflicts? * @param hasStar is the tuples contain star values? */ virtual void buildConstraintExtensionAs(string id, vector list, bool support, bool hasStar) { throw runtime_error("This extension constraint contains exactly the same tuples than previous one"); } /** * The callback function related to a constraint in intension * Only called if intensionUsingString is set to true (otherwise the next function is called * See http://xcsp.org/specifications/intension * Example: * eq(add(x,y),z) * If you need a class that is able to manage expressions you can use the class Tree (see includes/XCS3Tree.h) * And an example is given in samples/testTree.cc * In such a case, set intensionUsingString to false and make a callback to the next function * * @param id the id (name) of the constraint * @param expr the expression */ virtual void buildConstraintIntension(string id, string expr) { throw runtime_error("intension constraint is not yet supported"); } /** * The callback function related to a constraint in intension * Only called if intensionUsingString is set to false (otherwise the previous function is called * See http://xcsp.org/specifications/intension * Example: * eq(add(x,y),z) * * @param id the id (name) of the constraint * @param tree the canonized form related to the tree */ virtual void buildConstraintIntension(string id, Tree *tree) { throw runtime_error("intension constraint using a tree is not yet supported (choose the right way)"); } /** * If #recognizeSpecialIntensionCases is enabled (this is the case by default) * intensional constraint of the form : x +-k op y is recognized. * If such a intensional constraint is recognized, a callback to this function is done and not to #buildConstraintIntension * * @param id the id (name) of the constraint * @param op the order LE, LT... * @param x the variable * @param k the constant * @param y the other variable */ virtual void buildConstraintPrimitive(string id, OrderType op, XVariable *x, int k, XVariable *y) { throw runtime_error("primitive constraint x +-k op y is not yet supported. " "You can use classical intension constrain by assigning recognizeSpecialIntensionCases to false "); } /** * If #recognizeSpecialIntensionCases is enabled (this is the case by default) * intensional constraint of the form : x op k is recognized. * If such a intensional constraint is recognized, a callback to this function is done and not to #buildConstraintIntension * * @param id the id (name) of the constraint * @param op the order LE or GE (EQ and NE are performed using #buildConstrantExtension) * @param x the variable * @param k the constant */ virtual void buildConstraintPrimitive(string id, OrderType op, XVariable *x, int k) { throw runtime_error("primitive constraint x op k is not yet supported. " "You can use classical intension constrain by assigning recognizeSpecialIntensionCases to false "); } /** * If #recognizeSpecialIntensionCases is enabled (this is the case by default) * intensional constraint of the form : x in/notin [min max] are recognized * If such a intensional constraint is recognized, a callback to this function is done and not to #buildConstraintIntension * * @param id the id (name) of the constraint * @param x the variable * @param in true if x is in this interval * @param min the constant * @param max the constant * */ virtual void buildConstraintPrimitive(string id, XVariable *x, bool in, int min, int max) { throw runtime_error("primitive constraint x in/notin [min,max] is not yet supported. " "You can use classical intension constrain by assigning recognizeSpecialIntensionCases to false "); } //-------------------------------------------------------------------------------------- // Language constraints //-------------------------------------------------------------------------------------- /** * The callback function related to a regular constraint. * See http://xcsp.org/specifications/regular * Example: * * x1 x2 x3 x4 x5 x6 x7 * * (a,0,a)(a,1,b)(b,1,c)(c,0,d)(d,0,d)(d,1,e)(e,0,e) * * a * e * * XTransition is an object with 3 fields: from (string), val(int) and to(string) * Then, in the first transition of the example from=a, to=a and val=0 * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param start the starting node * @param final the set of final nodes * @param transitions the set of transitions */ virtual void buildConstraintRegular(string id, vector &list, string start, vector &final, vector &transitions) { throw runtime_error("regular constraint is not yet supported"); } /** * The callback function related to a MDD constraint. * See http://xcsp.org/specifications/mdd * * Example: * * x1 x2 x3 * * (r,0,n1)(r,1,n2)(r,2,n3) * (n1,2,n4)(n2,2,n4)(n3,0,n5) * (n4,0,t)(n5,0,t) * * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param transitions the set of transitions */ virtual void buildConstraintMDD(string id, vector &list, vector &transitions) { throw runtime_error("MDD constraint is not yet supported"); } //-------------------------------------------------------------------------------------- // Comparison constraints //-------------------------------------------------------------------------------------- /** * The callback function related to a alldifferent constraint. * See http://xcsp.org/specifications/alldifferent * * Example: * * x1 x2 x3 x4 x5 * * * @param id the id (name) of the constraint * @param list the scope of the constraint */ virtual void buildConstraintAlldifferent(string id, vector &list) { throw runtime_error("AllDiff constraint is not yet supported"); } /** * The callback function related to a alldifferent constraint with expression * See http://xcsp.org/specifications/alldifferent * * Example: * * add(q[0],0) add(q[1],1) add(q[2],2) add(q[3],3) add(q[4],4) add(q[5],5) add(q[6],6) add(q[7],7) * * * @param id the id (name) of the constraint * @param list the trees of the constraint */ virtual void buildConstraintAlldifferent(string id, vector &list) { throw runtime_error("AllDiff constraint with expression is not yet supported"); } /** * The callback function related to a alldifferent with some excepted values constraint * See http://xcsp.org/specifications/alldifferent * * Example: * * x1 x2 x3 x4 x5 * 0 * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param except the set of excepted values */ virtual void buildConstraintAlldifferentExcept(string id, vector &list, vector &except) { throw runtime_error("AllDiff constraint with exception is not yet supported"); } /** * The callback function related to a alldifferent list constraint * See http://xcsp.org/specifications/alldifferent * * Example: * * x1 x2 x3 x4 * y1 y2 y3 y4 * * * @param id the id (name) of the constraint * @param lists the set of lists (not the scope, a variable may appear at different place!) */ virtual void buildConstraintAlldifferentList(string id, vector> &lists) { throw runtime_error("AllDiff list constraint is not yet supported"); } /** * The callback function related to a alldifferent matrix constraint * See http://xcsp.org/specifications/alldifferent * * Example: * * * (x1,x2,x3,x4,x5) * (y1,y2,y3,y4,y5) * (z1,z2,z3,z4,z5) * * * * @param id the id (name) of the constraint * @param matrix the matrix (not the scope, a variable may appear at different place!) */ virtual void buildConstraintAlldifferentMatrix(string id, vector> &matrix) { throw runtime_error("AllDiff matrix constraint is not yet supported"); } /** * The callback function related to a allequal constraint * See http://xcsp.org/specifications/allEqual * * Example: * * x1 x2 x3 x4 x5 * * * @param id the id (name) of the constraint * @param list the scope of the constraint * */ virtual void buildConstraintAllEqual(string id, vector &list) { throw runtime_error("Allequal constraint is not yet supported"); } /** * The callback function related to a not all equal constraint * This is a special case of nvalues constraint * Recognized if #recognizeNValuesCases is enabled (this is the case by default) * See http://xcsp.org/specifications/nValues * * Example: * * x1 x2 x3 x4 * (gt,1) * * * @param id the id (name) of the constraint * @param list the scope of the constraint */ virtual void buildConstraintNotAllEqual(string id, vector &list) { throw runtime_error("NotAllequal constraint is not yet supported"); } /** * The callback function related to an ordered constraint * See http://xcsp.org/specifications/ordered * * Ordered is LE, LT, GE, GT... See OrderType in XCSPConstants.h * * Example: * * x1 x2 x3 x4 * lt * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param order the order LT, LE... */ virtual void buildConstraintOrdered(string id, vector &list, OrderType order) { throw runtime_error("Ordered constraint is not yet supported"); } /** * The callback function related to an ordered constraint * See http://xcsp.org/specifications/ordered * * Ordered is LE, LT, GE, GT... See OrderType in XCSPConstants.h * * Example: * * x1 x2 x3 x4 * lt * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param order the order LT, LE... */ virtual void buildConstraintOrdered(string id, vector &list, vector &lengths, OrderType order) { throw runtime_error("Ordered constraint with lengths is not yet supported"); } /** * The callback function related to an ordered list constraint (this is a lex constraint) * See http://xcsp.org/specifications/ordered * * * Example: * * x1 x2 x3 x4 * y1 y2 y3 y4 * lt * * * @param id the id (name) of the constraint * @param lists the set of lists (not the scope, a variable may appear at different place!) * @param order the order LT, LE... */ virtual void buildConstraintLex(string id, vector> &lists, OrderType order) { throw runtime_error("Lex constraint is not yet supported"); } /** * The callback function related to an ordered matrix constraint * See http://xcsp.org/specifications/ordered * * * Example: * * * (z1,z2,z3) * (z4,z5,z6) * (z7,z8,z9) * * lt * * * @param id the id (name) of the constraint * @param matrix the matrix (not the scope, a variable may appear at different place!) * @param order the order LT, LE... */ virtual void buildConstraintLexMatrix(string id, vector> &matrix, OrderType order) { throw runtime_error("Lex matrix constraint is not yet supported"); } //-------------------------------------------------------------------------------------- // Summing and counting constraints //-------------------------------------------------------------------------------------- /** * The callback function related to an sum constraint * See http://xcsp.org/specifications/sum * * XCondition is an object with on OrderType (LE, LT...) an operandType (INTEGER, INTERVAL or VARIABLE) * depending the value of this field, either val (if operandType is INTEGER), min/max (INTERVAL) or var (VARIABLE) * is useful. * Example: * * x1 x2 x3 * 1 2 3 * (gt,y) * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param coeffs the coefficients (here int) * @param cond the condition (See XCondition object) */ virtual void buildConstraintSum(string id, vector &list, vector &coeffs, XCondition &cond) { throw runtime_error("sum constraint is not yet supported"); } /** * The callback function related to an sum constraint with all coefs are equal to one * See http://xcsp.org/specifications/sum * * Example: * * x1 x2 x3 * (gt,y) * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param cond the condition (See XCondition object) */ virtual void buildConstraintSum(string id, vector &list, XCondition &cond) { throw runtime_error("unweighted sum constraint is not yet supported"); } /** * The callback function related to a sum constraint with all coefs are variables * See http://xcsp.org/specifications/sum * * Example: * * x1 x2 x3 * y1 y2 y3 * (gt,y) * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param coeffs the coefficients (here XVariable) * @param cond the condition (See XCondition object) */ virtual void buildConstraintSum(string id, vector &list, vector &coeffs, XCondition &cond) { throw runtime_error("sum constraint with variables weights is not yet supported"); } /** * The callback function related to a sum constraint with trees in list * * Example: * * or(eq(x[5],0),eq(x[7],0)) or(eq(x[1],0),eq(x[2],0),eq(x[8],0)) or(eq(x[0],0),eq(x[3],0),eq(x[4],0),eq(x[6],0),eq(x[9],0)) * (gt,y) * * * @param id the id (name) of the constraint * @param list the different trees * @param cond the condition (See XCondition object) */ virtual void buildConstraintSum(string id, vector &trees, XCondition &cond) { throw runtime_error("sum constraint with expressions not yet supported"); } /** * The callback function related to a sum constraint with trees in list * * Example: * * or(eq(x[5],0),eq(x[7],0)) or(eq(x[1],0),eq(x[2],0),eq(x[8],0)) or(eq(x[0],0),eq(x[3],0),eq(x[4],0),eq(x[6],0),eq(x[9],0)) * 1 2 3 * (gt,y) * * * @param id the id (name) of the constraint * @param list the different trees * @param coefs the coefs. * @param cond the condition (See XCondition object) */ virtual void buildConstraintSum(string id, vector &trees, vector &coefs, XCondition &cond) { throw runtime_error("sum constraint with expressions and coefs not yet supported"); } /** * The callback function related to a atmost constraint * This is a special count constraint * This callback is called if #recognizeSpecialCountCases is enabled (this is the case by default) * See http://xcsp.org/specifications/count * * * Example: * * y1 y2 y3 y4 * 0 * (le,2) * * * Here at most 2 variables from y1...y4 can have value 0 * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param value the value * @param k the maximum number of variables that can take the value */ virtual void buildConstraintAtMost(string id, vector &list, int value, int k) { throw runtime_error("atmost constraint is not yet supported"); } /** * The callback function related to a atleast constraint * This is a special count constraint * This callback is called if #recognizeSpecialCountCases is enabled * See http://xcsp.org/specifications/count * * * Example: * * x1 x2 x3 x4 x5 * 1 * (ge,3) * * * Here at least 3 variables from x1...x5 must have value 1 * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param value the value * @param k the minimum number of variables that can take the value */ virtual void buildConstraintAtLeast(string id, vector &list, int value, int k) { throw runtime_error("atleast constraint is not yet supported"); } /** * The callback function related to a exactly k constraint * This is a special count constraint * This callback is called if #recognizeSpecialCountCases is enabled * See http://xcsp.org/specifications/count * * * Example: * * z1 z2 z3 Z4 * 0 * (eq,2) * * Here exactly 2 variables from z1...z4 must have value 0 * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param value the value * @param k the exact number of variables that can take the value */ virtual void buildConstraintExactlyK(string id, vector &list, int value, int k) { throw runtime_error("exactly K constraint is not yet supported"); } /** * The callback function related to a exactly k variable constraint * This is a special count constraint * This callback is called if #recognizeSpecialCountCases is enabled * See http://xcsp.org/specifications/count * * * Example: * * z1 z2 z3 Z4 * 0 * (eq,z5) * * Here exactly z5 variables from z1...z4 must have value 0 * @param id the id (name) of the constraint * @param list the scope of the constraint * @param value the value * @param x the exact number of variables that can take the value (here it is a variable) */ virtual void buildConstraintExactlyVariable(string id, vector &list, int value, XVariable *x) { throw runtime_error("exactly Variable constraint is not yet supported"); } /** * The callback function related to a among constraint * This is a special count constraint * This callback is called if #recognizeSpecialCountCases is enabled * See http://xcsp.org/specifications/count * * * Example: * * w1 w2 w3 w4 * 1 5 8 * (eq,k2) * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param value the value * @param k */ virtual void buildConstraintAmong(string id, vector &list, vector &values, int k) {// TODO AMONG throw runtime_error("Among constraint is not yet supported"); } /** * The callback function related to a count constraint with integer values * See http://xcsp.org/specifications/count * Example: * * v1 v2 v3 v4 * 2 4 * (ne,k1) * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param value the set of values (here set of ints) * @param k the number of variables * @param xc the condition (see #XCondition) */ virtual void buildConstraintCount(string id, vector &list, vector &values, XCondition &xc) { throw runtime_error("count with integer values constraint is not yet supported"); } /** * The callback function related to a count constraint with integer variables * See http://xcsp.org/specifications/count * Example: * * v1 v2 v3 v4 * x1 x2 * (ne,k1) * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param value the set of values (here set of variables) * @param k the number of variables * @param xc the condition (see #XCondition) */ virtual void buildConstraintCount(string id, vector &list, vector &values, XCondition &xc) { throw runtime_error("count with variables values constraint is not yet supported"); } /** * The callback function related to a nValues constraint with exception * See http://xcsp.org/specifications/nValues * Example: * * z1 z2 z3 z4 * 0 * (eq,2) * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param except the set of excepted values * @param xc the condition (see #XCondition) */ virtual void buildConstraintNValues(string id, vector &list, vector &except, XCondition &xc) { throw runtime_error("NValues with exception constraint is not yet supported"); } /** * The callback function related to a nValues constraint with exception * See http://xcsp.org/specifications/nValues * Example: * * z1 z2 z3 z4 * (eq,2) * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param xc the condition (see #XCondition) */ virtual void buildConstraintNValues(string id, vector &list, XCondition &xc) { throw runtime_error("NValues constraint is not yet supported"); } /** * The callback function related to a cardinality constraint with int values and int occurs * See http://xcsp.org/specifications/cardinality * * Example: * * x1 x2 x3 x4 * 2 5 10 * 1 2 3 * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param values the set of values (here int) * @param occurs the number of occurences (here int) * @param closed is the constraint is closed */ virtual void buildConstraintCardinality(string id, vector &list, vector values, vector &occurs, bool closed) { throw runtime_error("cardinality with int values and int occurs constraint is not yet supported"); } // /** * The callback function related to a cardinality constraint with int values and variable occurs * See http://xcsp.org/specifications/cardinality * * Example: * * x1 x2 x3 x4 * 0 1 2 3 * z0 z1 z2 z3 * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param values the set of values (here int) * @param occurs the number of occurences (here variables) * @param closed is the constraint is closed */ virtual void buildConstraintCardinality(string id, vector &list, vector values, vector &occurs, bool closed) { throw runtime_error("cardinality with int values and int occurs constraint is not yet supported"); } // /** * The callback function related to a cardinality constraint with int values and interval occurs * See http://xcsp.org/specifications/cardinality * * Example: * * x1 x2 x3 x4 * 2 5 10 * 0..1 1..3 2..3 * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param values the set of values (here int) * @param occurs the number of occurences (here intervals) * @param closed is the constraint is closed */ virtual void buildConstraintCardinality(string id, vector &list, vector values, vector &occurs, bool closed) { throw runtime_error("cardinality with int values and int occurs constraint is not yet supported"); } /** * The callback function related to a cardinality constraint with variable values and int occurs * See http://xcsp.org/specifications/cardinality * * Example: * * x1 x2 x3 x4 * z1 z2 z3 * 1 2 3 * * * @param id the id (name) of the constraint * @param list the list of the constraint (not the scope...) * @param values the set of values (here variable) * @param occurs the number of occurences (here int) * @param closed is the constraint is closed */ virtual void buildConstraintCardinality(string id, vector &list, vector values, vector &occurs, bool closed) { throw runtime_error("cardinality with int values and int occurs constraint is not yet supported"); } /** * The callback function related to a cardinality constraint with variable values and variable occurs * See http://xcsp.org/specifications/cardinality * * Example: * * x1 x2 x3 x4 * z1 z2 z3 * y1 y2 y3 * * * @param id the id (name) of the constraint * @param list the list of the constraint (not the scope) * @param values the set of values (here variables) * @param occurs the number of occurences (here variables) * @param closed is the constraint is closed */ virtual void buildConstraintCardinality(string id, vector &list, vector values, vector &occurs, bool closed) { throw runtime_error("cardinality with int values and int occurs constraint is not yet supported"); } /** * The callback function related to a cardinality constraint with variable values and interval occurs * See http://xcsp.org/specifications/cardinality * * Example: * * x1 x2 x3 x4 * z1 z2 z3 * 1..2 3..5 2..4 * * * @param id the id (name) of the constraint * @param list the list of the constraint (not the scope) * @param values the set of values (here variables) * @param occurs the number of occurences (here intervals) * @param closed is the constraint is closed */ virtual void buildConstraintCardinality(string id, vector &list, vector values, vector &occurs, bool closed) { throw runtime_error("cardinality with int values and int occurs constraint is not yet supported"); } //-------------------------------------------------------------------------------------- // Connection constraints //-------------------------------------------------------------------------------------- /** * The callback function related to a minimum constraint * See http://xcsp.org/specifications/minimum * * Example: * * x1 x2 x3 x4 * (eq,y) * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param xc the condition (see #XCondition) */ virtual void buildConstraintMinimum(string id, vector &list, XCondition &xc) { throw runtime_error("minimum constraint is not yet supported"); } /** * The callback function related to a minimum constraint (arg_min) * See http://xcsp.org/specifications/minimum * * Example: * * x1 x2 x3 x4 * z1 * (eq,3) * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param index the index variable * @param startIndex 0 or something else ? * @param rank ANY, ALL... * @param xc the condition (see #XCondition) */ virtual void buildConstraintMinimum(string id, vector &list, XVariable *index, int startIndex, RankType rank, XCondition &xc) { throw runtime_error("minimum with index constraint is not yet supported"); } /** * The callback function related to a maximum constraint * See http://xcsp.org/specifications/maximum * * Example: * * x1 x2 x3 x4 * (ge,2) * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param xc the condition (see #XCondition) */ virtual void buildConstraintMaximum(string id, vector &list, XCondition &xc) { throw runtime_error("maximum constraint is not yet supported"); } /** * The callback function related to a maximum constraint (arg_max) * See http://xcsp.org/specifications/maximum * * Example: * * x1 x2 x3 x4 * z1 * (eq,3) * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param index the index variable * @param startIndex 0 or something else ? * @param rank ANY, ALL... * @param xc the condition (see #XCondition) */ virtual void buildConstraintMaximum(string id, vector &list, XVariable *index, int startIndex, RankType rank, XCondition &xc) { throw runtime_error("maximum with index constraint is not yet supported"); } /** * The callback function related to a element constraint with int value * See http://xcsp.org/specifications/element * * Example: * * y[] * 2 * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param value the value (here an int) */ virtual void buildConstraintElement(string id, vector &list, int value) { throw runtime_error("Element value constraint is not yet supported"); } /** * The callback function related to a element constraint with variable value * See http://xcsp.org/specifications/element * * Example: * * y[] * z * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param value the value (here a variable) */ virtual void buildConstraintElement(string id, vector &list, XVariable *value) { throw runtime_error("Element variable constraint is not yet supported"); } /** * The callback function related to a element constraint with variable index and int value * See http://xcsp.org/specifications/element * * Example: * * y[] * i * 2 * * * @param id the id (name) of the constraint * @param list the list of the constraint (not necessary the scope) * @param index the index variable * @param startIndex 0 or something else ? * @param rank ANY, ALL... * @param value the value (here an int) */ virtual void buildConstraintElement(string id, vector &list, int startIndex, XVariable *index, RankType rank, int value) { throw runtime_error("Element value with index constraint is not yet supported"); } /** * The callback function related to a element constraint with variable index and variable value * See http://xcsp.org/specifications/element * * Example: * * y[] * i * z * * * @param id the id (name) of the constraint * @param list the list of the constraint (not necessary the scope) * @param index the index variable * @param startIndex 0 or something else ? * @param rank ANY, ALL... * @param value the value (here a variable) */ virtual void buildConstraintElement(string id, vector &list, int startIndex, XVariable *index, RankType rank, XVariable *value) { throw runtime_error("Element variable with index constraint is not yet supported"); } /** * The callback function related to a element constraint with int list variable index and variable value * See http://xcsp.org/specifications/element * * Example: * * 1 2 3 4 * i * z * * * @param id the id (name) of the constraint * @param list the list of int * @param index the index variable * @param startIndex 0 or something else ? * @param rank ANY, ALL... * @param value the value (here a variable) */ virtual void buildConstraintElement(string id, vector &list, int startIndex, XVariable *index, RankType rank, XVariable *value) { throw runtime_error("Element value (with list of integers) with index constraint is not yet supported"); } /** * The callback function related to a channel constraint * See http://xcsp.org/specifications/channel * * Example: * * z1 z2 z3 z4 z5 * * * @param id the id (name) of the constraint * @param list the scope of the constraint */ virtual void buildConstraintChannel(string id, vector &list, int startIndex) { throw runtime_error("channel with 1 list constraint is not yet supported"); } /** * The callback function related to a channel constraint * See http://xcsp.org/specifications/channel * * Example: * * x1 x2 x3 x4 * y1 y2 y3 y4 * * * The size of the array {@code list1} must be less than or equal to the size of {@code list2}. * * If list1.size() == list2.size() then list1[i] = j <=> list2[j] = i * If list1.size() < list2.size() then list1[i] = j => list2[j] = i * * @param id the id (name) of the constraint * @param list1 the first list * @param startIndex1 the starting index for list1 * @param list2 the second list * @param startIndex2 the starting index for list2 * */ virtual void buildConstraintChannel(string id, vector &list1, int startIndex1, vector &list2, int startIndex2) { throw runtime_error("channel with 2 lists constraint is not yet supported"); } /** * The callback function related to a channel constraint with a value * See http://xcsp.org/specifications/channel * * Example: * * z1 z2 z3 z4 z5 * v * * * @param id the id (name) of the constraint * @param list the list of the constraint not necessary the scope) * @param startIndex the starting index for list * @param value the vaule */ virtual void buildConstraintChannel(string id, vector &list, int startIndex, XVariable *value) { throw runtime_error("channel with 1 list and 1 value constraint is not yet supported"); } //-------------------------------------------------------------------------------------- // packing and schedulling constraints //-------------------------------------------------------------------------------------- /** * The callback function related to a strectch constraint with values and widths * See http://xcsp.org/specifications/stretch * * Example: * * x1 x2 x3 x4 x5 x6 x7 * 1 2 3 0 * 1..3 1..3 2..3 2..4 * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param values thelist of values * @param widths the list of intervals for widths */ virtual void buildConstraintStretch(string id, vector &list, vector &values, vector &widths) { throw runtime_error("stretch constraint is not yet supported"); } /** * The callback function related to a strectch constraint with values, widths and patterns * See http://xcsp.org/specifications/stretch * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param values thelist of values * @param widths the list of intervals for widths * @param patterns * */ virtual void buildConstraintStretch(string id, vector &list, vector &values, vector &widths, vector> &patterns) { throw runtime_error("stretch constraint is not yet supported"); } /** * The callback function related to a no overlap constraint with variable origins and int lenghts * See http://xcsp.org/specifications/noOverlap * * Example: * * x1 x2 x3 * l1 l2 l3 * * * @param id the id (name) of the constraint * @param origins the vector of origins * @param lengths the vector of lenghts (here int) * @param zeroIgnored are zero ignored? */ virtual void buildConstraintNoOverlap(string id, vector &origins, vector &lengths, bool zeroIgnored) { throw runtime_error("nooverlap with int lengths constraint is not yet supported"); } /** * The callback function related to a no overlap constraint with variable origins and variable lenghts * See http://xcsp.org/specifications/noOverlap * * Example: * * x1 x2 x3 * z1 z2 z3 * * * @param id the id (name) of the constraint * @param origins the vector of origins * @param lengths the vector of lenghts (here variables) * @param zeroIgnored are zero ignored? */ virtual void buildConstraintNoOverlap(string id, vector &origins, vector &lengths, bool zeroIgnored) { throw runtime_error("nooverlap with variable lengths constraint is not yet supported"); } /** * The callback function related to a no overlap constraint with variable origins and 3 dimensional int lenghts * See http://xcsp.org/specifications/noOverlap * * Example: * * (x1,y1,z1)(x2,y2,z2)(x3,y3,z3)(x4,y4,z4) * (2,4,1)(4,2,3)(5,1,2)(3,3,2) * * * @param id the id (name) of the constraint * @param origins the vector of origins * @param lengths the vector of lenghts (here vector of int) * @param zeroIgnored are zero ignored? */ virtual void buildConstraintNoOverlap(string id, vector> &origins, vector> &lengths, bool zeroIgnored) { throw runtime_error("K dim nooverlap with int lengths constraint is not yet supported"); } /** * The callback function related to a no overlap constraint with variable origins and 3 dimensional variable lenghts * See http://xcsp.org/specifications/noOverlap * * Example: * * (x1,y1,z1)(x2,y2,z2)(x3,y3,z3)(x4,y4,z4) * (a,b,c)(d,e,f)(g,h,i)(l,m,n) * * * @param id the id (name) of the constraint * @param origins the vector of origins * @param lengths the vector of lenghts (here vector of variables) * @param zeroIgnored are zero ignored? */ virtual void buildConstraintNoOverlap(string id, vector> &origins, vector> &lengths, bool zeroIgnored) { throw runtime_error("K dim nooverlap with variable lengths constraint is not yet supported"); } /** * The callback function related to a cumulative constraint with variable origins, int lengths and int heights * See http://xcsp.org/specifications/cumulative * * Example: * * s1 s2 s3 s4 * 1 2 3 4 * 3 4 5 6 * (le,4) * * * @param id the id (name) of the constraint * @param origins the vector of origins * @param lengths the vector of lenghts (here ints) * @param heights the vector of heights (here ints) * @param xc the condition (see XCondition) */ virtual void buildConstraintCumulative(string id, vector &origins, vector &lengths, vector &heights, XCondition &xc) { throw runtime_error("cumulative (int lengths, int heights) constraint is not yet supported"); } /** * The callback function related to a cumulative constraint with variable origin, int lengths and variable heights * See http://xcsp.org/specifications/cumulative * * Example: * * s1 s2 s3 s4 * 1 2 3 4 * h1 h2 h3 h4 * (le,4) * * * @param id the id (name) of the constraint * @param origins the vector of origins * @param lengths the vector of lenghts (here ints) * @param heights the vector of heights (here variables) * @param xc the condition (see XCondition) */ virtual void buildConstraintCumulative(string id, vector &origins, vector &lengths, vector &varHeights, XCondition &xc) { throw runtime_error("cumulative (int lengths, var heights) constraint is not yet supported"); } /** * The callback function related to a cumulative constraint with variable origin, variable lengths and int heights * See http://xcsp.org/specifications/cumulative * * Example: * * s1 s2 s3 s4 * l1 l2 l3 l4 * 1 2 3 4 * (le,4) * * * @param id the id (name) of the constraint * @param origins the vector of origins * @param lengths the vector of lenghts (here variables) * @param heights the vector of heights (here ints) * @param xc the condition (see XCondition) */ virtual void buildConstraintCumulative(string id, vector &origins, vector &lengths, vector &heights, XCondition &xc) { throw runtime_error("cumulative (var lengths, int heights) constraint is not yet supported"); } /** * The callback function related to a cumulative constraint with variable origin, variable lengths and variable heights * See http://xcsp.org/specifications/cumulative * * Example: * * s1 s2 s3 s4 * l1 l2 l3 l4 * h1 h2 h3 h4 * (le,4) * * * @param id the id (name) of the constraint * @param origins the vector of origins * @param lengths the vector of lenghts (here variables) * @param heights the vector of heights (here variables) * @param xc the condition (see XCondition) */ virtual void buildConstraintCumulative(string id, vector &origins, vector &lengths, vector &heights, XCondition &xc) { throw runtime_error("cumulative (var lengths, var heights) constraint is not yet supported"); } /** * The callback function related to a cumulative constraint with variable origin, int lengths and int heights and variable ends * See http://xcsp.org/specifications/cumulative * * Example: * * s1 s2 s3 s4 * 1 2 3 4 * 1 2 3 4 * e1 e2 e3 e4 * (le,4) * * * @param id the id (name) of the constraint * @param origins the vector of origins * @param lengths the vector of lenghts (here ints) * @param heights the vector of heights (here ints) * @param ends the vector of ends (here variables) * @param xc the condition (see XCondition) */ virtual void buildConstraintCumulative(string id, vector &origins, vector &lengths, vector &heights, vector &ends, XCondition &xc) { throw runtime_error("cumulative (int lengths, int heights) constraint is not yet supported"); } /** * The callback function related to a cumulative constraint with variable origin, int lengths and variable heights and variable ends * See http://xcsp.org/specifications/cumulative * * Example: * * s1 s2 s3 s4 * 1 2 3 4 * h1 h2 h3 h4 * e1 e2 e3 e4 * (le,4) * * * @param id the id (name) of the constraint * @param origins the vector of origins * @param lengths the vector of lenghts (here ints) * @param heights the vector of heights (here variables) * @param ends the vector of ends (here variables) * @param xc the condition (see XCondition) */ virtual void buildConstraintCumulative(string id, vector &origins, vector &lengths, vector &varHeights, vector &ends, XCondition &xc) { throw runtime_error("cumulative (int lengths, var heights, ends) constraint is not yet supported"); } /** * The callback function related to a cumulative constraint with variable origin, variable lengths and int heights and variable ends * See http://xcsp.org/specifications/cumulative * * Example: * * s1 s2 s3 s4 * l1 l2 l3 l4 * 1 2 3 4 * e1 e2 e3 e4 * (le,4) * * * @param id the id (name) of the constraint * @param origins the vector of origins * @param lengths the vector of lenghts (here variables) * @param heights the vector of heights (here ints) * @param ends the vector of ends (here variables) * @param xc the condition (see XCondition) */ virtual void buildConstraintCumulative(string id, vector &origins, vector &lengths, vector &heights, vector &ends, XCondition &xc) { throw runtime_error("cumulative (var lengths, int heights, ends) constraint is not yet supported"); } /** * The callback function related to a cumulative constraint with variable origin, variable lengths and variable heights and variable ends * See http://xcsp.org/specifications/cumulative * * Example: * * s1 s2 s3 s4 * l1 l2 l3 l4 * h1 h2 h3 h4 * e1 e2 e3 e4 * (le,4) * * * @param id the id (name) of the constraint * @param origins the vector of origins * @param lengths the vector of lenghts (here variables) * @param heights the vector of heights (here variables) * @param ends the vector of ends (here variables) * @param xc the condition (see XCondition) */ virtual void buildConstraintCumulative(string id, vector &origins, vector &lengths, vector &heights, vector &ends, XCondition &xc) { throw runtime_error("cumulative (var lengths, var heights, ends) constraint is not yet supported"); } //-------------------------------------------------------------------------------------- // instantiation constraints //-------------------------------------------------------------------------------------- /** * The callback function related to an instantiation constraint * See http://xcsp.org/specifications/instantiation * * Example: * * x y z * 12 4 30 * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param values the value for each variable */ virtual void buildConstraintInstantiation(string id, vector &list, vector &values) { throw runtime_error("instantiation constraint not yet supported"); } //-------------------------------------------------------------------------------------- // Graph constraints //-------------------------------------------------------------------------------------- /** * The callback function related to circuit constraint * See http://xcsp.org/specifications/circuit * * Example: * * x y z * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param startIndex the start index for the list */ virtual void buildConstraintCircuit(string id, vector &list, int startIndex) { throw runtime_error("circuit constraint not yet supported"); } /** * The callback function related to circuit constraint with defined int size * See http://xcsp.org/specifications/circuit * * Example: * * x y z * 4 * * * @param id the id (name) of the constraint * @param list the scope of the constraint * @param startIndex the start index for the list * @param size the size of the circuit (here an int) */ virtual void buildConstraintCircuit(string id, vector &list, int startIndex, int size) { throw runtime_error("circuit constraint not yet supported"); } /** * The callback function related to circuit constraint with defined variable size * See http://xcsp.org/specifications/circuit * * Example: * * x y z * s * * * @param id the id (name) of the constraint * @param list the list of variables (not necessary the scope) * @param startIndex the start index for the list * @param size the size of the circuit (here an variable) */ virtual void buildConstraintCircuit(string id, vector &list, int startIndex, XVariable *size) { throw runtime_error("circuit constraint not yet supported"); } //-------------------------------------------------------------------------------------- // Objectives //-------------------------------------------------------------------------------------- /** * The callback function related to an objective minimize an expression * See http://xcsp.org/specifications/objectives * * Example: * * add(x,mul(y,2)) * * * @param expr the expression */ virtual void buildObjectiveMinimizeExpression(string expr) { throw runtime_error("minimize expression objective not yet supported"); } /** * The callback function related to an objective maximize an expression * See http://xcsp.org/specifications/objectives * * Example: * * add(x,2) * * * @param expr the expression */ virtual void buildObjectiveMaximizeExpression(string expr) { throw runtime_error("maximize expression objective not yet supported"); } /** * The callback function related to an objective minimize a variable * See http://xcsp.org/specifications/objectives * * Example: * * x * * * @param x the variable */ virtual void buildObjectiveMinimizeVariable(XVariable *x) { throw runtime_error("minimize variable objective not yet supported"); } /** * The callback function related to an objective maximize a variable * See http://xcsp.org/specifications/objectives * * Example: * * x * * * @param x the variable */ virtual void buildObjectiveMaximizeVariable(XVariable *x) { throw runtime_error("maximize variable objective not yet supported"); } /** * The callback function related to an objective minimize a sum/product * See http://xcsp.org/specifications/objectives * * Example: * * * x1 x2 x3 x4 x5 * 2 4 1 4 8 * * * * @param type SUM, PRODUCT... * @param list the scope * @param coefs the vector of coefficients */ virtual void buildObjectiveMinimize(ExpressionObjective type, vector &list, vector &coefs) { throw runtime_error("minimize objective sum... not yet supported"); } /** * The callback function related to an objective maximize a sum/product * See http://xcsp.org/specifications/objectives * * Example: * * * x1 x2 x3 x4 x5 * 2 4 1 4 8 * * * * @param type SUM, PRODUCT... * @param list the scope * @param coefs the vector of coefficients */ virtual void buildObjectiveMaximize(ExpressionObjective type, vector &list, vector &coefs) { throw runtime_error("maximize objective not yet supported"); } /** * The callback function related to an objective minimize a sum/product with coefs = 1 * See http://xcsp.org/specifications/objectives * * Example: * * * x1 x2 x3 x4 x5 * * * * @param type SUM, PRODUCT... * @param list the scope */ virtual void buildObjectiveMinimize(ExpressionObjective type, vector &list) { throw runtime_error("minimize objective not yet supported"); } /** * The callback function related to an objective maximize a sum/product with coefs = 1 * See http://xcsp.org/specifications/objectives * * Example: * * * x1 x2 x3 x4 x5 * * * * @param type SUM, PRODUCT... * @param list the scope */ virtual void buildObjectiveMaximize(ExpressionObjective type, vector &list) { throw runtime_error("maximize objective not yet supported"); } /** * The callback function related to annotations. * It provides the set of decision variables related to the problem. * @param list */ virtual void buildAnnotationDecision(vector &list) {} }; } #endif //COSOCO_XCSP3CORECALLBACKS_H