numberjack user guide
play

Numberjack User Guide May 27, 2013 1 Variables Constructor for the - PDF document

Numberjack User Guide May 27, 2013 1 Variables Constructor for the class Variable : Constructor Object Binary variable Variable() Variable in the domain of { 0, N-1 } Variable(N) Binary variable called x Variable(x) Variable in


  1. Numberjack User Guide May 27, 2013 1 Variables Constructor for the class Variable : Constructor Object Binary variable Variable() Variable in the domain of { 0, N-1 } Variable(N) Binary variable called ’x’ Variable(’x’) Variable in the domain of { 0, N-1 } called ’x’ Variable(N, ’x’) Variable in the domain of { l, u } Variable(l,u) Variable in the domain of { l, u } called ’x’ Variable(l,u, ’x’) Variable(list) Variable with domain specified as a list Variable(list, ’x’) Variable with domain specified as a list called ’x’ The class VarArray represents a list of Variable s. Constructor Object creates an array from a list l VarArray(l) creates an array of n Boolean variables VarArray(n) creates an array of n Boolean variables with names ’x0..xn-1’ VarArray(n, ’x’) creates an array of n variables with domains [0..m-1] and names ’x0..xn-1’ VarArray(n, m, ’x’) creates an array of n variables with domains [0..m-1] VarArray(n, m) creates an array of n variables with domains d and names ’x0..xn-1’ VarArray(n, d, ’x’) creates an array of n variables with domains d VarArray(n, d) VarArray(n, l, u, ’x’) creates an array of n variables with domains [l..u] and names ’x0..xn-1’ VarArray(n, l, u) creates an array of n variables with domains [l..u] The class Matrix represents a 2-dimensional array of Variable s. Constructor Object creates a Matrix from a list l Matrix(l) creates a n x m Matrix of Boolean variables Matrix(n, m) creates a n x m Matrix of Boolean variables with names ’x0.0..xn-1.m-1’ Matrix(n, m, ’x’) creates a n x m Matrix of variables with domains [0..u-1] Matrix(n, m, u) creates a n x m Matrix of variables with domains [0..u-1] and names ’x0.0..xn-1.m-1’ Matrix(n, m, u, ’x’) creates a n x m Matrix of variables with domains [l..u] Matrix(n, m, l, u) creates a n x m Matrix of variables with domains [l..u] and names ’x0.0..xn-1.m-1’ Matrix(n, m, l, u, ’x’) 1

  2. Operators These use the infix notation ( x ⊕ y where ⊕ is an operator). They return an Expression object that can be constrained. Operators in the first table must be used as expressions in another constraint. Symbol Arguments Value + Expression / Integer x , Expression / Integer y an Expression constrained to be equal to x + y − Expression / Integer x , Expression / Integer y an Expression constrained to be equal to x − y ∗ Expression / Integer x , Expression / Integer y an Expression constrained to be equal to x × y / Expression / Integer x , Expression / Integer y an Expression constrained to be equal to x/y % Expression / Integer x , Expression / Integer y an Expression constrained to be equal to x mod y Operators of the second table may be posted as constraints. In this case, if x is the returned Expression , the posted constraint will have the semantic x � = 0 (i.e., x is True ). Symbol Arguments Value == Expression / Integer x , Expression / Integer y a (Boolean) Expression constrained to be 1 iff x = y ! = Expression / Integer x , Expression / Integer y a (Boolean) Expression constrained to be 1 iff x � = y < = Expression / Integer x , Expression / Integer y a (Boolean) Expression constrained to be 1 iff x ≤ y < Expression / Integer x , Expression / Integer y a (Boolean) Expression constrained to be 1 iff x < y > = Expression / Integer x , Expression / Integer y a (Boolean) Expression constrained to be 1 iff x ≥ y > Expression / Integer x , Expression / Integer y a (Boolean) Expression constrained to be 1 iff x > y | Expression / Integer x , Expression / Integer y a (Boolean) Expression constrained to be 1 iff x � = 0 or y � = 0 & Expression / Integer x , Expression / Integer y a (Boolean) Expression constrained to be 1 iff x � = 0 and y � = 0 2

  3. Functions These are used as function (foo(args), where foo is the function and args the argunents). They return an Expression object that must be constrained. Symbol Arguments Value an Expression x an Expression constrained to be equal to | x | Abs an Expression x an Expression constrained to be equal to − x Neg an Expression constrained to be equal to � n a list of Expression s [ x 1 , . . . , x n ] i =1 a i x i Sum a list of Integer s [ a 1 , . . . , a n ] (default [1 , . . . , 1] ) a list of Expression s [ x 1 , . . . , x n ] an Expression constrained to be equal to min 1 ≤ i ≤ n x i Min a list of Expression s [ x 1 , . . . , x n ] an Expression constrained to be equal to max 1 ≤ i ≤ n x i Max a list of Expression s [ x 1 , . . . , x n ] an Expression constrained to be equal to x y Element * and an Expression y (*) Can be used with the square brackets operator is [ x 1 , . . . , x n ] is a VarArray X as follows: X [ y ] Constraints These are used as function (foo(args), where foo is the function and args the argunents), they are not expressions and cannot be constrained. Symbol Arguments Value a List of Expression s [ x 1 , . . . , x n ] Constrains the variables [ x 1 , . . . , x n ] to take pairwise AllDiff distinct values a List of Expression s [ x 1 , . . . , x n ] and a Dictionary Constrains each value v j in � 1 ≤ i ≤ n D ( x i ) to appear Gcc mapping each value v j in � 1 ≤ i ≤ n D ( x i ) to a pair ( l j , u j ) between l j and u j times in the sequence [ x 1 , . . . , x n ] Objectives These are used as function (foo(args), where foo is the function and args the argunents), they are not expressions and cannot be constrained. Only one objective can be added to the model. Symbol Arguments Value an Expression x Indicates that the value of x should be maximised Maximise an Expression x Indicates that the value of x should be minimised Minimise 3

  4. Variable Heuristics Set by the method setHeuristic(var-order, val-order, randomization) of Solver . The possible arguments for “var-order” are: Symbol Effect Branch on variables according to the input order ’Random’ Branch on variables according to the input order ’Lex’ Branch on variables according to the inverse of input order ’AntiLex’ Branch on the variable of highest dynamic degree first ’MaxDegree’ Branch on the variable with smallest domain first ’MinDomain’ Branch on the variable with smallest domain first, ties broken by minium min value ’MinDomainMinVal’ Branch on the variable with smallest domain first, ties broken by dynamic degree ’MinDomainMaxDegree’ Branch on the variable with smallest ratio (domain size / degree) ’DomainOverDegree’ Branch on the variable with smallest ratio (domain size / weighted degree) ’DomainOverWDegree’ Branch on the variable average (domain size / degree) over neighbouring variables ’Ngihbour’ ’Impact’ Branch on the variable of highest impact ’ImpactOverDegree’ Branch on the variable with smallest ratio (1 / (impact * degree)) ’ImpactOverDegree’ Branch on the variable with smallest ratio (1 / (impact * weighted degree)) The possible arguments for “val-order” are: Symbol Effect Select the minimum value in the domain ’Lex’ Select the maximum value in the domain ’AntiLex’ Select a value randomly with uniform probability ’Random’ Select either the minimum of maximum value randomly with uniform probability ’RandomMinMax’ Reduce the domain splitting around the average of the bounds ’DomainSplit’ Reduce the domain splitting around a random value ’RandomSplit’ ’Impact’ Select the value with minimum impact The randomization arguments indicates how many variables should be selected. The final choice is made randomly between them Solving Methods The standard way of calling the solver is the method solve(X) where X is a list of variables (or a VarArray or a Matrix ). If no value is given for X , all variables are branched on. It return True is a solution was found and False otherwise. The method solveAndRestart(X) works similarly as solve(X) , except that the search will be restarted after a number of failures. The methods startNewSearch(X) and getNextSolution() allow to find sevral solutions. startNewSearch(X) must be called once to initialise the procedure, then getNextSolution() can be called, finding a new solution at each call. 4

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend