├── LICENSE
├── README.md
├── build.gradle
├── doc
├── JvCSP3v1-1.pdf
├── checkerJava1-1.pdf
├── parserJava1-2.pdf
└── parserJava1-2.tex
├── instancesTest
├── AllInterval-005.xml.lzma
├── Allergy.xml.lzma
├── Bibd-sc-06-050-25-03-10.xml.lzma
├── Bibd-sum-06-050-25-03-10.xml.lzma
├── BinPacking-mdd-n1c1w4a.xml.lzma
├── BinPacking-sum-n1c1w4a.xml.lzma
├── BinPacking-tab-n1c1w4a.xml.lzma
├── Blackhole-04-3-00.xml.lzma
├── BusScheduling-cnt-t1.xml.lzma
├── CarSequencing-dingbas.xml.lzma
├── ChessboardColoration-07-07.xml.lzma
├── ColouredQueens-07.xml.lzma
├── CostasArray-12.xml.lzma
├── Crossword-lex-vg-5-6.xml.lzma
├── CryptoPuzzle-cross-roads-danger.xml.lzma
├── Cutstock-small.xml.lzma
├── DistinctVectors-30-050-02.xml.lzma
├── Domino-300-300.xml.lzma
├── Fastfood-ff10.xml.lzma
├── GolombRuler-09-a3.xml.lzma
├── GolombRuler-09-a4.xml.lzma
├── GracefulGraph-K02-P04.xml.lzma
├── GraphColoring-3-fullins-4.xml.lzma
├── GraphColoring-qwhdec-o5-h10-1.xml.lzma
├── Hanoi-05.xml.lzma
├── Kakuro-easy-000-ext.xml.lzma
├── Kakuro-easy-000-sumdiff.xml.lzma
├── Knapsack-30-100-00.xml.lzma
├── KnightTour-06-ext03.xml.lzma
├── KnightTour-06-int.xml.lzma
├── Langford-3-10.xml.lzma
├── LangfordBin-08.xml.lzma
├── LowAutocorrelation-015.xml.lzma
├── MagicSequence-008-ca.xml.lzma
├── MagicSequence-008-co.xml.lzma
├── MagicSquare-4-table.xml.lzma
├── MagicSquare-6-mdd.xml.lzma
├── MagicSquare-6-sum.xml.lzma
├── MagicSquare-9-f10-01.xml.lzma
├── Mario-easy-4.xml.lzma
├── MarketSplit-01.xml.lzma
├── MultiKnapsack-1-01.xml.lzma
├── MultiKnapsack-1-0_X2.xml.lzma
├── Nonogram-001-regular.xml.lzma
├── Nonogram-001-table.xml.lzma
├── Opd-07-007-003.xml.lzma
├── Ortholatin-005.xml.lzma
├── Pb-gr-05.xml.lzma
├── Pb-robin08.xml.lzma
├── Primes-15-20-2-1.xml.lzma
├── PrizeCollecting-15-3-5-0.xml.lzma
├── QuadraticAssignment-bur26a.xml.lzma
├── QuadraticAssignment-qap.xml.lzma
├── QuasiGroup-3-04.xml.lzma
├── QuasiGroup-7-09.xml.lzma
├── QueenAttacking-06.xml.lzma
├── Queens-0008-m1.xml.lzma
├── RadarSurveillance-8-24-3-2-00.xml.lzma
├── Ramsey-12.xml.lzma
├── RoomMate-sr0050-int.xml.lzma
├── Sat-flat200-00-clause.xml.lzma
├── SocialGolfers-4-3-4-cp.xml.lzma
├── SportsScheduling-08.xml.lzma
├── Steiner3-08.xml.lzma
├── StillLife-03-06.xml.lzma
├── StillLife-wastage-03.xml.lzma
├── StripPacking-C1P1.xml.lzma
├── Subisomorphism-A-10.xml.lzma
├── Sudoku-s01a-alldiff.xml.lzma
├── Taillard-js-015-15-0.xml.lzma
├── Taillard-os-04-04-0.xml.lzma
├── Tpp-3-3-20-1.xml.lzma
├── TravellingSalesman-20-30-00.xml.lzma
├── Vrp-A-n32-k5.xml.lzma
├── Vrp-P-n16-k8.xml.lzma
├── Warehouse-opl.xml.lzma
├── Zebra.xml.lzma
├── driverlogw-09.xml.lzma
├── qcp-15-120-00_X2.xml.lzma
├── qwh-o30-h374-01.xml.lzma
├── testExtension1.xml.lzma
├── testExtension2.xml.lzma
├── testExtension3.xml.lzma
├── testObjective1.xml.lzma
└── testPrimitive.xml.lzma
├── pom.xml
└── src
├── main
└── java
│ └── org
│ └── xcsp
│ ├── common
│ ├── Condition.java
│ ├── Constants.java
│ ├── FunctionalInterfaces.java
│ ├── IVar.java
│ ├── Range.java
│ ├── Size.java
│ ├── Softening.java
│ ├── Types.java
│ ├── Utilities.java
│ ├── domains
│ │ ├── Domains.java
│ │ └── Values.java
│ ├── enumerations
│ │ ├── EnumerationAbstract.java
│ │ ├── EnumerationCartesian.java
│ │ ├── EnumerationOfCombinations.java
│ │ └── EnumerationOfPermutations.java
│ ├── predicates
│ │ ├── MatcherInterface.java
│ │ ├── TreeEvaluator.java
│ │ ├── XNode.java
│ │ ├── XNodeLeaf.java
│ │ ├── XNodeParent.java
│ │ └── XNodeParentSpecial.java
│ └── structures
│ │ ├── AbstractTuple.java
│ │ ├── Automaton.java
│ │ ├── Table.java
│ │ ├── TableAbstract.java
│ │ ├── TableSymbolic.java
│ │ ├── Transition.java
│ │ └── Transitions.java
│ ├── modeler
│ ├── Compiler.java
│ ├── api
│ │ ├── ProblemAPI.java
│ │ ├── ProblemAPIBase.java
│ │ ├── ProblemAPIOnVals.java
│ │ ├── ProblemAPIOnVars.java
│ │ └── ProblemAPISymbolic.java
│ ├── definitions
│ │ ├── DefXCSP.java
│ │ ├── ICtr.java
│ │ ├── IObj.java
│ │ └── IRootForCtrAndObj.java
│ ├── entities
│ │ ├── CtrEntities.java
│ │ ├── ModelingEntity.java
│ │ ├── ObjEntities.java
│ │ └── VarEntities.java
│ ├── implementation
│ │ ├── NotData.java
│ │ ├── ProblemDataHandler.java
│ │ ├── ProblemIMP.java
│ │ └── ProblemIMP3.java
│ └── problems
│ │ ├── AllInterval.java
│ │ ├── Bibd.java
│ │ ├── Blackhole.java
│ │ ├── BoardColoration.java
│ │ ├── MagicSequence.java
│ │ ├── Pic.java
│ │ ├── Pic2.java
│ │ ├── Queens.java
│ │ ├── Rack.java
│ │ ├── Rack2.java
│ │ ├── Riddle.java
│ │ ├── Riddle2.java
│ │ ├── Riddle3.java
│ │ ├── Riddle4.java
│ │ ├── Riddle4b.java
│ │ ├── Riddle5.java
│ │ ├── Sudoku.java
│ │ ├── Warehouse.java
│ │ └── Zebra.java
│ └── parser
│ ├── WrongTypeException.java
│ ├── XParser.java
│ ├── callbacks
│ ├── CompetitionValidator.java
│ ├── FeatureDisplayer.java
│ ├── SolutionChecker.java
│ ├── XCallbacks.java
│ └── XCallbacks2.java
│ ├── entries
│ ├── ParsingEntry.java
│ ├── XConstraints.java
│ ├── XObjectives.java
│ └── XVariables.java
│ └── loaders
│ ├── ConstraintRecognizer.java
│ ├── CtrLoaderInteger.java
│ └── CtrLoaderSymbolic.java
└── test
└── java
└── TestSolutions.java
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016-2023, Univ. Artois and CNRS
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
XCSP3-Java-Tools v2.5.1
2 |
3 |
4 |
5 | This library provides:
6 | * a parser written in Java 8 for XCSP3 instances ; see [miniguide](doc/parserJava1-2.pdf)
7 | * a tool for checking solutions (and bounds) of XCSP3 instances ; see [miniguide](doc/checkerJava1-1.pdf)
8 |
9 | A C++ parser is available in its own [repository](https://github.com/xcsp3team/XCSP3-CPP-Parser).
10 |
11 | A Python library for modeling, called PyCSP3, is also independently available.
12 | For the current version of PyCSP3, note that:
13 | * a website including more than 60 Jupyter notebooks can be found at [pycsp.org](https://pycsp.org).
14 | * the code is available on [Github](https://github.com/xcsp3team/pycsp3)
15 | * a [well-documented guide](https://arxiv.org/abs/2009.00326) is available
16 | * PyCSP3 is available as a PyPi package [here](https://pypi.org/project/pycsp3/)
17 | * a GitHub repository with more than 340 models is available at [pycsp3-models](https://github.com/xcsp3team/pycsp3-models)
18 |
19 | # 1) Documentation
20 |
21 | Information about XCSP3 can be found at [xcsp.org](https://xcsp.org).
22 |
23 | For details about these tools, see the documents referenced below.
24 |
25 | ## Java Parser
26 |
27 | See the miniguide in file [`parserJava1-2.pdf`](doc/parserJava1-2.pdf).
28 |
29 | ## Solution Checker
30 |
31 | See the miniguide in file [`checkerJava1-1.pdf`](doc/checkerJava1-1.pdf).
32 |
33 |
34 |
35 |
36 | # 2) Obtaining Binary and Sources of XCSP3 Tools
37 |
38 | ## Maven Artifact
39 |
40 | You can get it at the [Central Repository](https://search.maven.org).
41 | Currently, this is:
42 |
43 |
44 | org.xcsp
45 | xcsp3-tools
46 | 2.5.1
47 |
48 |
49 | ## Directly Building a JAR with Maven
50 |
51 | 1. Clone the repository : `git clone https://github.com/xcsp3team/XCSP3-Java-Tools.git`
52 | 1. Change directory : `cd XCSP3-Java-Tools`
53 | 1. Run Maven : `mvn package -Dmaven.test.skip=true` (of course, you need Maven to be installed)
54 | 1. Test the JARs in the directory 'target'. For example, while choosing the right value for X-Y-Z,
55 | - `java -cp target/xcsp3-tools-X-Y-Z.jar org.xcsp.modeler.Compiler`. If the usage of the compiler is displayed, you are fine.
56 |
57 | You can also directly hit a main method:
58 | - `java -jar target/xcsp3-compiler-X-Y-Z.jar`
59 | - `java -jar target/xcsp3-solutionChecker-X-Y-Z.jar`
60 | - `java -jar target/xcsp3-competitionValidator-X-Y-Z.jar`
61 |
62 | ## Directly Building a JAR with Gradle
63 |
64 | 1. Clone the repository : `git clone https://github.com/xcsp3team/XCSP3-Java-Tools.git`
65 | 1. Change directory : `cd XCSP3-Java-Tools`
66 | 1. Run Gradle : `gradle build -x test` (of course, you need Gradle to be installed)
67 | 1. Test the JAR : `java -cp build/libs/xcsp3-tools-X-Y-Z.jar org.xcsp.modeler.Compiler` (choose the right values for X-Y-Z)
68 | If the usage of the compiler is displayed, you are fine.
69 |
70 | With this JAR, you can run the compiler (JvCSP3) and the solution checker.
71 | See details in the documents, referenced above.
72 |
73 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 |
3 | sourceCompatibility = 1.8
4 | targetCompatibility = 1.8
5 |
6 | archivesBaseName = "xcsp3-tools"
7 | version = '2.5.1'
8 |
9 | repositories {
10 | mavenCentral()
11 | }
12 |
13 | dependencies {
14 | compile group: 'org.glassfish', name: 'javax.json', version: '1.1.2'
15 | //compile files('lib/javax.json-1.0.4.jar')
16 | testCompile 'junit:junit:4.12'
17 | }
18 |
19 |
20 |
21 | jar {
22 | duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/doc/JvCSP3v1-1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/doc/JvCSP3v1-1.pdf
--------------------------------------------------------------------------------
/doc/checkerJava1-1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/doc/checkerJava1-1.pdf
--------------------------------------------------------------------------------
/doc/parserJava1-2.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/doc/parserJava1-2.pdf
--------------------------------------------------------------------------------
/instancesTest/AllInterval-005.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/AllInterval-005.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Allergy.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Allergy.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Bibd-sc-06-050-25-03-10.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Bibd-sc-06-050-25-03-10.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Bibd-sum-06-050-25-03-10.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Bibd-sum-06-050-25-03-10.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/BinPacking-mdd-n1c1w4a.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/BinPacking-mdd-n1c1w4a.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/BinPacking-sum-n1c1w4a.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/BinPacking-sum-n1c1w4a.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/BinPacking-tab-n1c1w4a.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/BinPacking-tab-n1c1w4a.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Blackhole-04-3-00.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Blackhole-04-3-00.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/BusScheduling-cnt-t1.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/BusScheduling-cnt-t1.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/CarSequencing-dingbas.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/CarSequencing-dingbas.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/ChessboardColoration-07-07.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/ChessboardColoration-07-07.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/ColouredQueens-07.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/ColouredQueens-07.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/CostasArray-12.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/CostasArray-12.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Crossword-lex-vg-5-6.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Crossword-lex-vg-5-6.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/CryptoPuzzle-cross-roads-danger.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/CryptoPuzzle-cross-roads-danger.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Cutstock-small.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Cutstock-small.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/DistinctVectors-30-050-02.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/DistinctVectors-30-050-02.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Domino-300-300.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Domino-300-300.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Fastfood-ff10.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Fastfood-ff10.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/GolombRuler-09-a3.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/GolombRuler-09-a3.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/GolombRuler-09-a4.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/GolombRuler-09-a4.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/GracefulGraph-K02-P04.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/GracefulGraph-K02-P04.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/GraphColoring-3-fullins-4.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/GraphColoring-3-fullins-4.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/GraphColoring-qwhdec-o5-h10-1.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/GraphColoring-qwhdec-o5-h10-1.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Hanoi-05.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Hanoi-05.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Kakuro-easy-000-ext.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Kakuro-easy-000-ext.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Kakuro-easy-000-sumdiff.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Kakuro-easy-000-sumdiff.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Knapsack-30-100-00.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Knapsack-30-100-00.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/KnightTour-06-ext03.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/KnightTour-06-ext03.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/KnightTour-06-int.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/KnightTour-06-int.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Langford-3-10.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Langford-3-10.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/LangfordBin-08.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/LangfordBin-08.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/LowAutocorrelation-015.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/LowAutocorrelation-015.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/MagicSequence-008-ca.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/MagicSequence-008-ca.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/MagicSequence-008-co.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/MagicSequence-008-co.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/MagicSquare-4-table.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/MagicSquare-4-table.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/MagicSquare-6-mdd.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/MagicSquare-6-mdd.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/MagicSquare-6-sum.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/MagicSquare-6-sum.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/MagicSquare-9-f10-01.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/MagicSquare-9-f10-01.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Mario-easy-4.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Mario-easy-4.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/MarketSplit-01.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/MarketSplit-01.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/MultiKnapsack-1-01.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/MultiKnapsack-1-01.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/MultiKnapsack-1-0_X2.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/MultiKnapsack-1-0_X2.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Nonogram-001-regular.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Nonogram-001-regular.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Nonogram-001-table.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Nonogram-001-table.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Opd-07-007-003.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Opd-07-007-003.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Ortholatin-005.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Ortholatin-005.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Pb-gr-05.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Pb-gr-05.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Pb-robin08.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Pb-robin08.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Primes-15-20-2-1.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Primes-15-20-2-1.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/PrizeCollecting-15-3-5-0.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/PrizeCollecting-15-3-5-0.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/QuadraticAssignment-bur26a.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/QuadraticAssignment-bur26a.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/QuadraticAssignment-qap.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/QuadraticAssignment-qap.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/QuasiGroup-3-04.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/QuasiGroup-3-04.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/QuasiGroup-7-09.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/QuasiGroup-7-09.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/QueenAttacking-06.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/QueenAttacking-06.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Queens-0008-m1.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Queens-0008-m1.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/RadarSurveillance-8-24-3-2-00.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/RadarSurveillance-8-24-3-2-00.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Ramsey-12.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Ramsey-12.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/RoomMate-sr0050-int.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/RoomMate-sr0050-int.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Sat-flat200-00-clause.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Sat-flat200-00-clause.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/SocialGolfers-4-3-4-cp.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/SocialGolfers-4-3-4-cp.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/SportsScheduling-08.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/SportsScheduling-08.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Steiner3-08.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Steiner3-08.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/StillLife-03-06.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/StillLife-03-06.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/StillLife-wastage-03.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/StillLife-wastage-03.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/StripPacking-C1P1.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/StripPacking-C1P1.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Subisomorphism-A-10.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Subisomorphism-A-10.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Sudoku-s01a-alldiff.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Sudoku-s01a-alldiff.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Taillard-js-015-15-0.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Taillard-js-015-15-0.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Taillard-os-04-04-0.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Taillard-os-04-04-0.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Tpp-3-3-20-1.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Tpp-3-3-20-1.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/TravellingSalesman-20-30-00.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/TravellingSalesman-20-30-00.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Vrp-A-n32-k5.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Vrp-A-n32-k5.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Vrp-P-n16-k8.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Vrp-P-n16-k8.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Warehouse-opl.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Warehouse-opl.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/Zebra.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/Zebra.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/driverlogw-09.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/driverlogw-09.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/qcp-15-120-00_X2.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/qcp-15-120-00_X2.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/qwh-o30-h374-01.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/qwh-o30-h374-01.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/testExtension1.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/testExtension1.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/testExtension2.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/testExtension2.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/testExtension3.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/testExtension3.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/testObjective1.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/testObjective1.xml.lzma
--------------------------------------------------------------------------------
/instancesTest/testPrimitive.xml.lzma:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xcsp3team/XCSP3-Java-Tools/e0a4321cbc75b552e6cfd854847c2f2577dc6298/instancesTest/testPrimitive.xml.lzma
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | org.xcsp
5 | xcsp3-tools
6 | 2.5.1
7 | jar
8 |
9 | XCSP3 Java Tools
10 | Java Tools for parsing XCSP3 instances, compiling JvCSP3 models, and checking solutions. For more information about XCSP3, follow www.xcsp.org
11 | https://www.xcsp.org
12 |
13 |
14 |
15 | MIT License
16 | http://www.opensource.org/licenses/mit-license.php
17 |
18 |
19 |
20 |
21 | Centre de Recherche en Informatique de Lens (CRIL), University of Artois
22 | https://www.cril.univ-artois.fr/
23 |
24 |
25 |
26 |
27 | Christophe Lecoutre
28 | lecoutre@cril.fr
29 | Univ. Artois, CRIL-CNRS
30 | http://www.cril.univ-artois.fr
31 |
32 | architect
33 | developer
34 |
35 | +1
36 |
37 |
38 | Gilles Audemard
39 | audemard@cril.fr
40 | Univ. Artois, CRIL-CNRS
41 | http://www.cril.univ-artois.fr
42 |
43 | developer
44 |
45 | +1
46 |
47 |
48 |
49 |
50 |
51 | Emmanuel Lonca
52 | lonca@cril.fr
53 | Univ. Artois, CRIL-CNRS
54 | http://www.cril.fr
55 |
56 |
57 |
58 |
59 | scm:git:git://github.com/xcsp3team/XCSP3-Java-Tools.git
60 | scm:git:ssh://github.com/xcsp3team/XCSP3-Java-Tools.git
61 | https://github.com/xcsp3team/XCSP3-Java-Tools/tree/master
62 |
63 |
64 |
65 | UTF-8
66 |
67 |
68 |
69 |
70 |
71 | javax.json
72 | javax.json-api
73 | 1.1.2
74 |
75 |
76 |
77 | org.glassfish
78 | javax.json
79 | 1.1.2
80 |
81 |
82 | junit
83 | junit
84 | 4.13.1
85 |
86 |
87 |
88 |
89 |
90 | ossrh
91 | https://oss.sonatype.org/content/repositories/snapshots
92 |
93 |
94 | ossrh
95 | https://oss.sonatype.org/service/local/staging/deploy/maven2/
96 |
97 |
98 |
99 |
100 |
101 | disable-java8-doclint
102 |
103 | [1.8,)
104 |
105 |
106 | -Xdoclint:none
107 |
108 |
109 |
110 |
111 |
112 | src/main/java
113 |
114 |
115 | org.apache.maven.plugins
116 | maven-release-plugin
117 | 2.5.3
118 |
119 | true
120 | false
121 | release
122 | deploy
123 |
124 |
125 |
126 | org.apache.maven.plugins
127 | maven-compiler-plugin
128 | 3.6.0
129 |
130 | 1.8
131 | 1.8
132 |
133 |
134 |
135 | org.apache.maven.plugins
136 | maven-source-plugin
137 | 2.2.1
138 |
139 |
140 | attach-sources
141 |
142 | jar-no-fork
143 |
144 |
145 |
146 |
147 |
148 | org.apache.maven.plugins
149 | maven-javadoc-plugin
150 | 2.9.1
151 |
152 |
153 | attach-javadocs
154 |
155 | jar
156 |
157 |
158 |
159 |
160 |
161 | org.apache.maven.plugins
162 | maven-gpg-plugin
163 | 1.5
164 |
165 |
166 | sign-artifacts
167 | verify
168 |
169 | sign
170 |
171 |
172 |
173 |
174 |
175 | maven-assembly-plugin
176 | 2.4
177 |
178 |
179 | competition-validator
180 |
181 | false
182 | false
183 |
184 |
185 | org.xcsp.parser.callbacks.CompetitionValidator
186 |
187 |
188 |
189 | jar-with-dependencies
190 |
191 | xcsp3-competitionValidator-${project.version}
192 |
193 | package
194 |
195 | single
196 |
197 |
198 |
199 | feature-displayer
200 |
201 | false
202 | false
203 |
204 |
205 | org.xcsp.parser.callbacks.FeatureDisplayer
206 |
207 |
208 |
209 | jar-with-dependencies
210 |
211 | xcsp3-featureDisplayer-${project.version}
212 |
213 | package
214 |
215 | single
216 |
217 |
218 |
219 | solution-checker
220 |
221 | false
222 | false
223 |
224 |
225 | org.xcsp.parser.callbacks.SolutionChecker
226 |
227 |
228 |
229 | jar-with-dependencies
230 |
231 | xcsp3-solutionChecker-${project.version}
232 |
233 | package
234 |
235 | single
236 |
237 |
238 |
239 |
240 | modeler-compiler
241 |
242 | false
243 | false
244 |
245 |
246 | org.xcsp.modeler.Compiler
247 |
248 |
249 |
250 | jar-with-dependencies
251 |
252 | xcsp3-compiler-${project.version}
253 |
254 | package
255 |
256 | single
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
--------------------------------------------------------------------------------
/src/main/java/org/xcsp/common/Constants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 XCSP3 Team (contact@xcsp.org)
3 | *
4 | * 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
5 | * the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
6 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7 | *
8 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9 | *
10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
11 | * 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
12 | * 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.
13 | */
14 | package org.xcsp.common;
15 |
16 | import java.math.BigInteger;
17 |
18 | /**
19 | * @author Christophe Lecoutre
20 | */
21 | public interface Constants {
22 | String EMPTY_STRING = "";
23 |
24 | String REG_WS = "\\s+";
25 | String WHITE_SPACE = " \t\n\r\f";
26 |
27 | // For each primitive type, we can safely use all values except the extreme ones (as defined by SAFETY_MARGIN)
28 | // so as to be able to use special values (for example, for representing +infinity and -infinity)
29 | int SAFETY_MARGIN = 10;
30 | long MIN_SAFE_BYTE = Byte.MIN_VALUE + SAFETY_MARGIN, MAX_SAFE_BYTE = Byte.MAX_VALUE - SAFETY_MARGIN;
31 | long MIN_SAFE_SHORT = Short.MIN_VALUE + SAFETY_MARGIN, MAX_SAFE_SHORT = Short.MAX_VALUE - SAFETY_MARGIN;
32 | long MIN_SAFE_INT = Integer.MIN_VALUE + SAFETY_MARGIN, MAX_SAFE_INT = Integer.MAX_VALUE - SAFETY_MARGIN;
33 | long MIN_SAFE_LONG = Long.MIN_VALUE + SAFETY_MARGIN, MAX_SAFE_LONG = Long.MAX_VALUE - SAFETY_MARGIN;
34 | BigInteger BIG_MIN_SAFE_LONG = BigInteger.valueOf(MIN_SAFE_LONG), BIG_MAX_SAFE_LONG = BigInteger.valueOf(MAX_SAFE_LONG);
35 |
36 | long MINUS_INFINITY = Long.MIN_VALUE;
37 | long PLUS_INFINITY = Long.MAX_VALUE;
38 | int MINUS_INFINITY_INT = Integer.MIN_VALUE;
39 | int PLUS_INFINITY_INT = Integer.MAX_VALUE;
40 | String MINUS_INFINITY_STRING = "-infinity";
41 | String PLUS_INFINITY_STRING = "+infinity";
42 |
43 | int ALL = Integer.MAX_VALUE;
44 |
45 | // We use the maximum value of each primitive type, minus 1, to denote STAR (related to the concept of short tuples)
46 | String STAR_SYMBOL = "*";
47 |
48 | byte STAR_BYTE = Byte.MAX_VALUE - 1;
49 | short STAR_SHORT = Short.MAX_VALUE - 1;
50 | int STAR_INT = Integer.MAX_VALUE - 1;
51 | long STAR_LONG = Long.MAX_VALUE - 1;
52 | int STAR = STAR_INT;
53 |
54 | public final String TIMES = "x";
55 |
56 | /** We use the minimum long value, plus 1, to denote that a value is outside bounds (e.g., of a domain) */
57 | long OUTSIDE_BOUNDS = Long.MIN_VALUE + 1;
58 |
59 | // Constants used for some first-level elements of the instances
60 | String INSTANCE = "instance";
61 | String VARIABLES = "variables";
62 | String VAR = "var";
63 | String ARRAY = "array";
64 | String DOMAIN = "domain";
65 | String REQUIRED = "required";
66 | String POSSIBLE = "possible";
67 | String CONSTRAINTS = "constraints";
68 | String BLOCK = "block";
69 | String GROUP = "group";
70 | String ARGS = "args";
71 | String OBJECTIVES = "objectives";
72 | String OBJECTIVE = "objective";
73 | String MINIMIZE = "minimize";
74 | String MAXIMIZE = "maximize";
75 | String SOFT = "soft";
76 | String ANNOTATIONS = "annotations";
77 | String DECISION = "decision";
78 | String VAL_HEURISTIC = "valHeuristic";
79 | String STATIC = "static";
80 |
81 | /** A regex for denoting delimiters used in lists (elements separated by commas and surrounded by parentheses) */
82 | String DELIMITER_LISTS = "\\s*\\)\\s*\\(\\s*|\\s*\\(\\s*|\\s*\\)\\s*";
83 |
84 | /** A regex for denoting delimiters used in sets (elements separated by a comma and surrounded by brace brackets) */
85 | String DELIMITER_SETS = "\\s*\\}\\s*\\{\\s*|\\s*\\{\\s*|\\s*\\}\\s*";
86 |
87 | /** A regex for denoting delimiters used in msets (elements separated by a comma and surrounded by double brace brackets) */
88 | String DELIMITER_MSETS = "\\s*\\}\\}\\s*\\{\\{\\s*|\\s*\\{\\{\\s*|\\s*\\}\\}\\s*";
89 |
90 | String[] KEYWORDS = { "neg", "abs", "add", "sub", "mul", "div", "mod", "sqr", "pow", "min", "max", "dist", "lt", "le", "ge", "gt", "ne", "eq", "set", "in",
91 | "not", "and", "or", "xor", "iff", "imp", "if", "card", "union", "inter", "diff", "sdiff", "hull", "djoint", "subset", "subseq", "supseq", "supset",
92 | "convex", "PI", "E", "fdiv", "fmod", "sqrt", "nroot", "exp", "ln", "log", "sin", "cos", "tan", "asin", "acos", "atan", "sinh", "cosh", "tanh",
93 | "others" };
94 | }
95 |
--------------------------------------------------------------------------------
/src/main/java/org/xcsp/common/IVar.java:
--------------------------------------------------------------------------------
1 | package org.xcsp.common;
2 |
3 | /**
4 | * This is the root interface of any variable, handled either in the parser or the modeler.
5 | */
6 | public interface IVar {
7 | /**
8 | * Returns the id (unique name) of the variable.
9 | *
10 | * @return the id (unique name) of the variable
11 | */
12 | String id();
13 |
14 | default String idPrefix() {
15 | String id = id();
16 | int pos = id.indexOf('[');
17 | return pos == -1 ? id : id.substring(0, pos);
18 | }
19 |
20 | /**
21 | * This is the root interface of any integer variable, handled either in the parser or the modeler. One could have expected that the name be
22 | * {@code IVarInteger}, but this would be annoying when modeling.
23 | */
24 | interface Var extends IVar {
25 | long firstValue();
26 |
27 | long lastValue();
28 |
29 | Object allValues();
30 |
31 | default boolean isZeroOne() {
32 | return false;
33 | }
34 | }
35 |
36 | /**
37 | * This is the root interface of any symbolic variable, handled either in the parser or the modeler. One could have expected that the name is
38 | * {@code IVarSymbolic}, but we prefer to keep simple names for modeling.
39 | */
40 | interface VarSymbolic extends IVar {
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/src/main/java/org/xcsp/common/Size.java:
--------------------------------------------------------------------------------
1 | package org.xcsp.common;
2 |
3 | /**
4 | * This is the root abstract class of all subclasses that are useful for denoting the size (i.e., length of each dimension) of
5 | * multi-dimensional arrays of variables. These classes are used as syntactic sugar.
6 | */
7 | public abstract class Size {
8 | /**
9 | * The respective lengths of an array of dimension {@code lengths.length}.
10 | */
11 | public int[] lengths;
12 |
13 | /**
14 | * Sets the lengths of the dimensions of an array of dimension {@code lengths.length}
15 | *
16 | * @param lengths
17 | * the lengths of the dimensions of an array
18 | * @return this object (for method chaining)
19 | */
20 | protected Size setLengths(int... lengths) {
21 | this.lengths = lengths;
22 | return this;
23 | }
24 |
25 | @Override
26 | public String toString() {
27 | return Utilities.join(lengths);
28 | }
29 |
30 | /**
31 | * A class for representing the size (length) of a 1-dimensional array. This is mainly used as syntactic sugar.
32 | */
33 | public static class Size1D extends Size {
34 | /**
35 | * Builds an object that represents the size (length) of a 1-dimensional array.
36 | *
37 | * @param length
38 | * the size (length) of the array
39 | * @return an object that represents the size (length) of a 1-dimensional array
40 | */
41 | public static Size1D build(int length) {
42 | return (Size1D) new Size1D().setLengths(length);
43 | }
44 | }
45 |
46 | /**
47 | * A class for representing the size (i.e., length of each dimension) a 2-dimensional array. This is mainly used as syntactic sugar.
48 | */
49 | public static class Size2D extends Size {
50 | /**
51 | * Builds an object that represents the size (i.e., length of each dimension) of a 2-dimensional array.
52 | *
53 | * @param length0
54 | * the size (length) of the first dimension of a 2-dimensional array
55 | * @param length1
56 | * the size (length) of the second dimension of a 2-dimensional array
57 | * @return an object that represents the size (i.e., length of each dimension) of a 2-dimensional array
58 | */
59 | public static Size2D build(int length0, int length1) {
60 | return (Size2D) new Size2D().setLengths(length0, length1);
61 | }
62 | }
63 |
64 | /**
65 | * A class for representing the size (i.e., length of each dimension) a 3-dimensional array. This is mainly used as syntactic sugar.
66 | */
67 | public static class Size3D extends Size {
68 | /**
69 | * Builds an object that represents the size (i.e., length of each dimension) of a 3-dimensional array.
70 | *
71 | * @param length0
72 | * the size (length) of the first dimension of a 3-dimensional array
73 | * @param length1
74 | * the size (length) of the second dimension of a 3-dimensional array
75 | * @param length2
76 | * the size (length) of the third dimension of a 3-dimensional array
77 | * @return an object that represents the size (i.e., length of each dimension) of a 3-dimensional array
78 | */
79 | public static Size3D build(int length0, int length1, int length2) {
80 | return (Size3D) new Size3D().setLengths(length0, length1, length2);
81 | }
82 | }
83 |
84 | /**
85 | * A class for representing the size (i.e., length of each dimension) a 4-dimensional array. This is mainly used as syntactic sugar.
86 | */
87 | public static class Size4D extends Size {
88 | /**
89 | * Builds an object that represents the size (i.e., length of each dimension) of a 4-dimensional array.
90 | *
91 | * @param length0
92 | * the size (length) of the first dimension of a 4-dimensional array
93 | * @param length1
94 | * the size (length) of the second dimension of a 4-dimensional array
95 | * @param length2
96 | * the size (length) of the third dimension of a 4-dimensional array
97 | * @param length3
98 | * the size (length) of the fourth dimension of a 4-dimensional array
99 | * @return an object that represents the size (i.e., length of each dimension) of a 4-dimensional array
100 | */
101 | public static Size4D build(int length0, int length1, int length2, int length3) {
102 | return (Size4D) new Size4D().setLengths(length0, length1, length2, length3);
103 | }
104 | }
105 |
106 | /**
107 | * A class for representing the size (i.e., length of each dimension) a 5-dimensional array. This is mainly used as syntactic sugar.
108 | */
109 | public static class Size5D extends Size {
110 | /**
111 | * Builds an object that represents the size (i.e., length of each dimension) of a 5-dimensional array.
112 | *
113 | * @param length0
114 | * the size (length) of the first dimension of a 5-dimensional array
115 | * @param length1
116 | * the size (length) of the second dimension of a 5-dimensional array
117 | * @param length2
118 | * the size (length) of the third dimension of a 5-dimensional array
119 | * @param length3
120 | * the size (length) of the fourth dimension of a 5-dimensional array
121 | * @param length4
122 | * the size (length) of the fifth dimension of a 5-dimensional array
123 | * @return an object that represents the size (i.e., length of each dimension) of a 5-dimensional array
124 | */
125 | public static Size5D build(int length0, int length1, int length2, int length3, int length4) {
126 | return (Size5D) new Size5D().setLengths(length0, length1, length2, length3, length4);
127 | }
128 | }
129 |
130 | }
131 |
--------------------------------------------------------------------------------
/src/main/java/org/xcsp/common/Softening.java:
--------------------------------------------------------------------------------
1 | package org.xcsp.common;
2 |
3 | import org.xcsp.common.Types.TypeMeasure;
4 |
5 | /** The root class used for representing softening. */
6 | public abstract class Softening {
7 |
8 | /** A pair (operator,operand) for a cost-integrated soft constraint, or null for a cost function. */
9 | public final Condition cost;
10 |
11 | public boolean isCostFunction() {
12 | return cost == null;
13 | }
14 |
15 | public Softening(Condition cost) {
16 | this.cost = cost;
17 | }
18 |
19 | public Softening() {
20 | this(null);
21 | }
22 |
23 | @Override
24 | public String toString() {
25 | return "Softening (" + this.getClass().getSimpleName() + ")" + " " + (cost == null ? "" : "cost:" + cost);
26 | }
27 |
28 | /** The class used for representing softening of simple soft constraints. */
29 | public static final class SofteningSimple extends Softening {
30 |
31 | /** The cost to be considered when the underlying constraint is violated. */
32 | public final int violationCost;
33 |
34 | public SofteningSimple(Condition cost, int violationCost) {
35 | super(cost);
36 | this.violationCost = violationCost;
37 | Utilities.control(violationCost > 0, "Pb with violation cost " + violationCost);
38 | }
39 |
40 | public SofteningSimple(int violationCost) {
41 | this(null, violationCost);
42 | }
43 |
44 | @Override
45 | public String toString() {
46 | return super.toString() + " violationCost=" + violationCost;
47 | }
48 | }
49 |
50 | /** The class used for representing softening of intensional constraints (that are not simple soft constraints). */
51 | public static final class SofteningIntension extends Softening {
52 |
53 | public SofteningIntension(Condition cost) {
54 | super(cost);
55 | }
56 |
57 | public SofteningIntension() {
58 | this(null);
59 | }
60 | }
61 |
62 | /** The class used for representing softening of extensional constraints (that are not simple soft constraints). */
63 | public static final class SofteningExtension extends Softening {
64 | /** The default cost for all tuples not explicitly listed. -1 if not useful (because all tuples are explicitly listed). */
65 | public final int defaultCost;
66 |
67 | public SofteningExtension(Condition cost, int defaultCost) {
68 | super(cost);
69 | this.defaultCost = defaultCost;
70 | Utilities.control(defaultCost >= -1, "Pb with default cost " + defaultCost);
71 | }
72 |
73 | public SofteningExtension(int defaultCost) {
74 | this(null, defaultCost);
75 | }
76 |
77 | @Override
78 | public String toString() {
79 | return super.toString() + " defaultCost=" + defaultCost;
80 | }
81 | }
82 |
83 | /** The class used for representing softening of other constraints (global constraints and some meta-constraints). */
84 | public static final class SofteningGlobal extends Softening {
85 | public final TypeMeasure type;
86 |
87 | public final String parameters;
88 |
89 | public SofteningGlobal(Condition cost, TypeMeasure type, String parameters) {
90 | super(cost);
91 | this.type = type;
92 | this.parameters = parameters;
93 | }
94 |
95 | public SofteningGlobal(Condition cost, TypeMeasure type) {
96 | this(cost, type, null);
97 | }
98 |
99 | public SofteningGlobal(TypeMeasure type, String parameters) {
100 | this(null, type, parameters);
101 | }
102 |
103 | public SofteningGlobal(TypeMeasure type) {
104 | this(type, null);
105 | }
106 |
107 | @Override
108 | public String toString() {
109 | return super.toString() + " type=" + type + (parameters != null ? " parameters=" + parameters : "");
110 | }
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/src/main/java/org/xcsp/common/enumerations/EnumerationAbstract.java:
--------------------------------------------------------------------------------
1 | /**
2 | * AbsCon - Copyright (c) 2017, CRIL-CNRS - lecoutre@cril.fr
3 | *
4 | * All rights reserved.
5 | *
6 | * This program and the accompanying materials are made available under the terms of the CONTRAT DE LICENCE DE LOGICIEL
7 | * LIBRE CeCILL which accompanies this distribution, and is available at http://www.cecill.info
8 | */
9 | package org.xcsp.common.enumerations;
10 |
11 | import java.util.ArrayList;
12 | import java.util.Iterator;
13 | import java.util.List;
14 | import java.util.function.Consumer;
15 | import java.util.function.Predicate;
16 |
17 | import org.xcsp.common.Utilities;
18 |
19 | /**
20 | * This class is the root class for all subclasses allowing us to iterate over combinations, permutations, ...
21 | */
22 | public abstract class EnumerationAbstract implements Iterator {
23 |
24 | /**
25 | * Indicates if the method {@code hasNext()} has already been called. This is not the case if the value of this field is {@code null}. Otherwise, the value
26 | * of this field indicates the presence ({@code Boolean.TRUE}) or the absence ({@code Boolean.FALSE}) of another tuple already computed.
27 | */
28 | protected Boolean nextTuple;
29 |
30 | /**
31 | * The current tuple composed of indexes (of values)
32 | */
33 | public final int[] currTupleOfIdxs;
34 |
35 | /**
36 | * The current tuple composed of values
37 | */
38 | private final int[] currTupleOfVals;
39 |
40 | /**
41 | * Indicates if indexes match values (i.e., if the value at index {@code i} is always {@code i}).
42 | */
43 | protected final boolean indexesMatchValues;
44 |
45 | /**
46 | * Builds an object that can be used for enumerating tuples, each of them with the specified length.
47 | *
48 | * @param tupleLength
49 | * the length of each tuple in the enumeration
50 | * @param indexesMatchValues
51 | * {@code true} iff indexes (of values) and values match, i.e. if the value at index {@code i} is always {@code i})
52 | */
53 | public EnumerationAbstract(int tupleLength, boolean indexesMatchValues) {
54 | this.currTupleOfIdxs = new int[tupleLength];
55 | this.currTupleOfVals = new int[tupleLength];
56 | this.indexesMatchValues = indexesMatchValues;
57 | }
58 |
59 | /**
60 | * Computes the first tuple (called at reset time).
61 | */
62 | protected abstract void computeFirstTuple();
63 |
64 | /**
65 | * Resets the object, so as to be able to iterate again over all tuples of the enumeration.
66 | */
67 | public void reset() {
68 | nextTuple = Boolean.TRUE; // true because the first tuple is computed just below
69 | computeFirstTuple();
70 | }
71 |
72 | /**
73 | * Returns the value of the current tuple at the specified position.
74 | *
75 | * @param pos
76 | * the position of an integer in the tuple
77 | * @return the value of the current tuple at the specified position
78 | */
79 | protected abstract int valAt(int pos);
80 |
81 | private int[] vals() {
82 | if (indexesMatchValues)
83 | return currTupleOfIdxs;
84 | for (int i = 0; i < currTupleOfVals.length; i++)
85 | currTupleOfVals[i] = valAt(i);
86 | return currTupleOfVals;
87 | }
88 |
89 | @Override
90 | public abstract boolean hasNext();
91 |
92 | /**
93 | * {@inheritDoc} DO NOT MODIFY the tuple that is returned.
94 | */
95 | @Override
96 | public int[] next() {
97 | if (nextTuple == null)
98 | hasNext(); // determine if there is another tuple by computing it
99 | int[] t = nextTuple == Boolean.FALSE ? null : vals();
100 | nextTuple = nextTuple == Boolean.FALSE ? Boolean.FALSE : null;
101 | return t;
102 | }
103 |
104 | public void execute(Consumer c) {
105 | reset();
106 | while (hasNext()) {
107 | int[] t = next();
108 | c.accept(t);
109 | }
110 | }
111 |
112 | /**
113 | * Returns an array with all tuples that can be enumerated while being accepted by the specified predicate.
114 | *
115 | * @param p
116 | * a predicate used to test the tuples in the enumeration
117 | * @return an array with all tuples that can be enumerated while being accepted by the specified predicate
118 | */
119 | public int[][] toArray(Predicate p) {
120 | reset();
121 | List list = new ArrayList<>();
122 | while (hasNext()) {
123 | int[] x = next();
124 | if (p.test(x))
125 | list.add(x.clone());
126 | }
127 | return list.stream().toArray(int[][]::new);
128 | }
129 |
130 | /**
131 | * Returns an array with all tuples that can be enumerated. The array is lexicographically sorted.
132 | *
133 | * @return an array with all tuples that can be enumerated
134 | */
135 | public int[][] toArray() {
136 | reset();
137 | List list = new ArrayList<>();
138 | while (hasNext())
139 | list.add(next().clone());
140 | return list.stream().sorted(Utilities.lexComparatorInt).toArray(int[][]::new);
141 | }
142 |
143 | /**
144 | * Displays all tuples of this enumeration.
145 | */
146 | public void displayAllTuples() {
147 | reset();
148 | int cnt = 0;
149 | while (hasNext()) {
150 | System.out.println("(" + Utilities.join(next(), ",") + ") ");
151 | cnt++;
152 | }
153 | System.out.println("\nThere are " + cnt + " tuples");
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/src/main/java/org/xcsp/common/enumerations/EnumerationCartesian.java:
--------------------------------------------------------------------------------
1 | /**
2 | * AbsCon - Copyright (c) 2017, CRIL-CNRS - lecoutre@cril.fr
3 | *
4 | * All rights reserved.
5 | *
6 | * This program and the accompanying materials are made available under the terms of the CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL which accompanies this
7 | * distribution, and is available at http://www.cecill.info
8 | */
9 | package org.xcsp.common.enumerations;
10 |
11 | import java.util.ArrayList;
12 | import java.util.Arrays;
13 | import java.util.LinkedHashMap;
14 | import java.util.List;
15 | import java.util.Map;
16 | import java.util.stream.IntStream;
17 | import java.util.stream.Stream;
18 |
19 | import org.xcsp.common.Utilities;
20 |
21 | /**
22 | * This class allows iterating over all tuples of a given length from a given set of numbers (of possibilities at each position). Execute the main
23 | * method for an illustration.
24 | */
25 | public class EnumerationCartesian extends EnumerationAbstract {
26 |
27 | private static Map cacheOfTuples;
28 |
29 | /**
30 | * Returns an array with all tuples of the specified length such that for each tuple:
31 | *
32 | * - at each position, a value is between 0 (inclusive) and {@code nValues} (exclusive)
33 | * - all values are all different
34 | * - the sum of the values in the tuple is equal to the specified limit
35 | *
36 | *
37 | * @param limit
38 | * the integer denoting the limit of the sum
39 | * @param nValues
40 | * indicates how many values are possible at each position
41 | * @param tupleLength
42 | * the length of each tuple in the enumeration
43 | * @param offset
44 | * the value that must be systematically added to each value of each tuple
45 | * @return an array with all tuples of the specified length that respect a sum equality and an allDifferent restriction
46 | */
47 | public static int[][] tuplesWithDiffValuesSummingTo(int limit, int nValues, int tupleLength, int offset) {
48 | if (cacheOfTuples == null)
49 | cacheOfTuples = new LinkedHashMap<>();
50 | String key = limit + "_" + nValues + "_" + tupleLength + "_" + offset;
51 | int[][] tuples = cacheOfTuples.get(key);
52 | if (tuples != null)
53 | return tuples;
54 | List list = new ArrayList<>();
55 | int[][] combinations = new EnumerationOfCombinations(nValues, tupleLength).toArray();
56 | int[][] permutations = new EnumerationOfPermutations(tupleLength).toArray();
57 | for (int[] t : combinations) {
58 | if (offset != 0)
59 | for (int i = 0; i < t.length; i++)
60 | t[i] += offset;
61 | if (IntStream.of(t).sum() == limit)
62 | for (int[] perm : permutations)
63 | list.add(IntStream.range(0, t.length).map(i -> t[perm[i]]).toArray());
64 | }
65 | tuples = list.stream().sorted(Utilities.lexComparatorInt).toArray(int[][]::new);
66 | cacheOfTuples.put(key, tuples);
67 | return tuples;
68 | }
69 |
70 | /**********************************************************************************************
71 | * End of static section
72 | *********************************************************************************************/
73 |
74 | /**
75 | * Gives the sets of values on which the tuples will be built. {@code values[i]} is a 1-dimensional array with all possibles (ordered) values at
76 | * position {@code i} in a tuple.
77 | */
78 | protected final int[][] values;
79 |
80 | /**
81 | * Builds an object that can be used for enumerating tuples, using the specified sets of values. If the specified Boolean is {@code true} the
82 | * specified 2-dimensional array is cloned.
83 | *
84 | * @param values
85 | * the sets of values on which the tuples will be built
86 | * @param clone
87 | * if {@code true} the specified 2-dimensional array is cloned
88 | */
89 | public EnumerationCartesian(int[][] values, boolean clone) {
90 | super(values.length, Stream.of(values).allMatch(t -> IntStream.range(0, t.length).allMatch(i -> t[i] == i)));
91 | this.values = clone ? Stream.of(values).map(t -> t.clone()).toArray(int[][]::new) : values;
92 | Utilities.control(Stream.of(values).allMatch(t -> t.length > 0 && IntStream.range(0, t.length - 1).allMatch(i -> t[i] < t[i + 1])),
93 | "values are not correctly formed (order,...)");
94 | reset();
95 | }
96 |
97 | /**
98 | * Builds an object that can be used for enumerating tuples, using the specified sets of values.
99 | *
100 | * @param values
101 | * the sets of values on which the tuples will be built
102 | */
103 | public EnumerationCartesian(int[][] values) {
104 | this(values, true);
105 | }
106 |
107 | /**
108 | * Builds an object that can be used for enumerating tuples, using the specified numbers of values. Each tuple will contain a value at position
109 | * {@code i} in the range 0 to {@code nValues[i].length-1}.
110 | *
111 | * @param nValues
112 | * indicates how many values are possible at each position
113 | */
114 | public EnumerationCartesian(int... nValues) {
115 | this(IntStream.range(0, nValues.length).mapToObj(i -> IntStream.range(0, nValues[i]).toArray()).toArray(int[][]::new), false);
116 | }
117 |
118 | /**
119 | * Builds an object that can be used for enumerating tuples, using the specified numbers of values. Each tuple has the specified length and will
120 | * contain a value at position {@code i} in the range 0 to {@code nValues-1}.
121 | *
122 | * @param nValues
123 | * the number of values used to form tuples
124 | * @param tupleLength
125 | * the length of each tuple
126 | */
127 | public EnumerationCartesian(int nValues, int tupleLength) {
128 | this(IntStream.range(0, tupleLength).map(i -> nValues).toArray());
129 | }
130 |
131 | @Override
132 | protected int valAt(int i) {
133 | return values[i][currTupleOfIdxs[i]];
134 | }
135 |
136 | @Override
137 | protected void computeFirstTuple() {
138 | Arrays.fill(currTupleOfIdxs, 0);
139 | }
140 |
141 | @Override
142 | public boolean hasNext() {
143 | if (nextTuple != null)
144 | return nextTuple == Boolean.TRUE;
145 | for (int i = values.length - 1; i >= 0; i--)
146 | if (currTupleOfIdxs[i] + 1 == values[i].length)
147 | currTupleOfIdxs[i] = 0;
148 | else {
149 | currTupleOfIdxs[i]++;
150 | nextTuple = Boolean.TRUE;
151 | return true;
152 | }
153 | nextTuple = Boolean.FALSE;
154 | return false;
155 | }
156 |
157 | public static void main(String[] args) {
158 | new EnumerationCartesian(7, 7, 7, 7).displayAllTuples();
159 | new EnumerationCartesian(new int[][] { { 2, 3, 4 }, { 1, 5 }, { 12, 20 } }).displayAllTuples();
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/src/main/java/org/xcsp/common/enumerations/EnumerationOfCombinations.java:
--------------------------------------------------------------------------------
1 | /**
2 | * AbsCon - Copyright (c) 2017, CRIL-CNRS - lecoutre@cril.fr
3 | *
4 | * All rights reserved.
5 | *
6 | * This program and the accompanying materials are made available under the terms of the CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL which accompanies this
7 | * distribution, and is available at http://www.cecill.info
8 | */
9 | package org.xcsp.common.enumerations;
10 |
11 | import java.util.stream.IntStream;
12 |
13 | import org.xcsp.common.Utilities;
14 |
15 | /**
16 | * This class allows us to iterate over all combinations of a given length from a given set of values. Execute the main method for an illustration.
17 | */
18 | public class EnumerationOfCombinations extends EnumerationCartesian {
19 |
20 | /**
21 | * Indicates if the numbers of possible values at each position are all equal.
22 | */
23 | private final boolean uniform;
24 |
25 | /**
26 | * Builds an object that can be used for enumerating combinations, using the specified numbers of values.
27 | *
28 | * @param nValues
29 | * the number of possible different values at each position of the tuples. These numbers must be in an increasing order (and are
30 | * usually all equal)
31 | */
32 | public EnumerationOfCombinations(int[] nValues) {
33 | super(nValues);
34 | this.uniform = IntStream.range(1, nValues.length).allMatch(i -> nValues[i] == nValues[0]);
35 | Utilities.control(IntStream.range(0, nValues.length - 1).allMatch(i -> nValues[i] <= nValues[i + 1]), "Numbers are not in an increasing order");
36 | }
37 |
38 | /**
39 | * Builds an object that can be used for enumerating combinations, using the specified number of values. Each tuple (combination) has the
40 | * specified length.
41 | *
42 | * @param nValues
43 | * the number of values used to form combinations
44 | * @param tupleLength
45 | * the length of each combination
46 | */
47 | public EnumerationOfCombinations(int nValues, int tupleLength) {
48 | this(IntStream.range(0, tupleLength).map(i -> nValues).toArray());
49 | }
50 |
51 | @Override
52 | protected void computeFirstTuple() {
53 | for (int i = 0; nextTuple == Boolean.TRUE && i < values.length; i++)
54 | if (i >= values[i].length)
55 | nextTuple = Boolean.FALSE;
56 | else
57 | currTupleOfIdxs[i] = i;
58 | }
59 |
60 | /**
61 | * Determines if it is possible to extend the current tuple from the given position
62 | */
63 | private boolean isExtensibleFrom(int pos) {
64 | if (uniform)
65 | return (values[pos].length - currTupleOfIdxs[pos] > values.length - pos);
66 | int value = currTupleOfIdxs[pos];
67 | for (int i = pos; i < currTupleOfIdxs.length; i++)
68 | if (++value >= values[i].length)
69 | return false;
70 | return true;
71 | }
72 |
73 | @Override
74 | public boolean hasNext() {
75 | if (nextTuple != null)
76 | return nextTuple == Boolean.TRUE;
77 | int last = values.length - 1;
78 | while (last >= 0)
79 | if (!isExtensibleFrom(last))
80 | last--;
81 | else {
82 | currTupleOfIdxs[last] = currTupleOfIdxs[last] + 1;
83 | for (int i = last + 1; i < values.length; i++)
84 | currTupleOfIdxs[i] = currTupleOfIdxs[i - 1] + 1;
85 | nextTuple = Boolean.TRUE;
86 | return true;
87 | }
88 | nextTuple = Boolean.FALSE;
89 | return false;
90 | }
91 |
92 | public static void main(String[] args) {
93 | new EnumerationOfCombinations(7, 4).displayAllTuples();
94 | new EnumerationOfCombinations(new int[] { 3, 4, 4, 5 }).displayAllTuples();
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/org/xcsp/common/enumerations/EnumerationOfPermutations.java:
--------------------------------------------------------------------------------
1 | /**
2 | * AbsCon - Copyright (c) 2017, CRIL-CNRS - lecoutre@cril.fr
3 | *
4 | * All rights reserved.
5 | *
6 | * This program and the accompanying materials are made available under the terms of the CONTRAT DE LICENCE DE LOGICIEL
7 | * LIBRE CeCILL which accompanies this distribution, and is available at http://www.cecill.info
8 | */
9 | package org.xcsp.common.enumerations;
10 |
11 | import java.util.Arrays;
12 | import java.util.stream.IntStream;
13 |
14 | import org.xcsp.common.Utilities;
15 |
16 | /**
17 | * This class allows us to iterate over all permutations of a given set of integer values. See the Johnson-Trotter algorithm (H. F. Trotter[1962], S.
18 | * M. Johnson[1963]). Execute the main method for an illustration.
19 | */
20 | public class EnumerationOfPermutations extends EnumerationAbstract {
21 |
22 | /**
23 | * The values used to form permutations.
24 | */
25 | private final int[] values;
26 |
27 | private final boolean[] currDirectionOfIndexes; // false=left ; true =right
28 |
29 | /**
30 | * Builds an object that can be used for enumerating permutations, using the specified array of values.
31 | *
32 | * @param values
33 | * the values used to form permutations
34 | */
35 | public EnumerationOfPermutations(int... values) {
36 | super(values.length, IntStream.range(0, values.length).allMatch(i -> i == values[i]));
37 | this.values = values;
38 | this.currDirectionOfIndexes = new boolean[values.length];
39 | Utilities.control(IntStream.of(values).distinct().count() == values.length, "Values should all be different");
40 | reset();
41 | }
42 |
43 | /**
44 | * Builds an object that can be used for enumerating permutations, using the specified number of values. All values are taken in the range 0 to
45 | * {@code nValues-1}.
46 | *
47 | * @param nValues
48 | * the number of values used to form permutations
49 | */
50 | public EnumerationOfPermutations(int nValues) {
51 | this(IntStream.range(0, nValues).toArray());
52 | }
53 |
54 | @Override
55 | protected int valAt(int i) {
56 | return values[currTupleOfIdxs[i]];
57 | }
58 |
59 | @Override
60 | protected void computeFirstTuple() {
61 | for (int i = 0; i < currTupleOfIdxs.length; i++)
62 | currTupleOfIdxs[i] = i;
63 | Arrays.fill(currDirectionOfIndexes, false);
64 |
65 | }
66 |
67 | private int findLargestMobileIndexPosition() {
68 | int best = -1;
69 | for (int p = 0; p < currTupleOfIdxs.length; p++) {
70 | int q = currDirectionOfIndexes[p] ? p + 1 : p - 1;
71 | if (q < 0 || q > currTupleOfIdxs.length - 1)
72 | continue;
73 | if (currTupleOfIdxs[p] > currTupleOfIdxs[q])
74 | if (best == -1 || currTupleOfIdxs[p] > currTupleOfIdxs[best])
75 | best = p;
76 | }
77 | return best;
78 | }
79 |
80 | @Override
81 | public boolean hasNext() {
82 | if (nextTuple != null)
83 | return nextTuple == Boolean.TRUE;
84 | int p = findLargestMobileIndexPosition();
85 | if (p == -1) {
86 | nextTuple = Boolean.FALSE;
87 | return false;
88 | }
89 | int q = currDirectionOfIndexes[p] ? p + 1 : p - 1;
90 | int tmp = currTupleOfIdxs[p];
91 | boolean tmpD = currDirectionOfIndexes[p];
92 | currTupleOfIdxs[p] = currTupleOfIdxs[q];
93 | currDirectionOfIndexes[p] = currDirectionOfIndexes[q];
94 | currTupleOfIdxs[q] = tmp;
95 | currDirectionOfIndexes[q] = tmpD;
96 | for (int i = 0; i < currDirectionOfIndexes.length; i++)
97 | if (currTupleOfIdxs[i] > tmp)
98 | currDirectionOfIndexes[i] = !currDirectionOfIndexes[i];
99 | nextTuple = Boolean.TRUE;
100 | return true;
101 | }
102 |
103 | // @Override
104 | // public int[][] toArray() {
105 | // reset();
106 | // int nPermutations = Utilities.factorial(values.length);
107 | // int[][] m = new int[nPermutations][values.length];
108 | // int cnt = 0;
109 | // while (hasNext()) {
110 | // m[cnt] = next().clone();
111 | // cnt++;
112 | // }
113 | // return Stream.of(m).sorted(Utilities.lexComparatorInt).toArray(int[][]::new);
114 | // }
115 |
116 | public static void main(String[] args) {
117 | new EnumerationOfPermutations(1, 2, 3, 4, 5).displayAllTuples();
118 | new EnumerationOfPermutations(3).displayAllTuples();
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/src/main/java/org/xcsp/common/predicates/MatcherInterface.java:
--------------------------------------------------------------------------------
1 | package org.xcsp.common.predicates;
2 |
3 | import static org.xcsp.common.Types.TypeExpr.ABS;
4 | import static org.xcsp.common.Types.TypeExpr.ADD;
5 | import static org.xcsp.common.Types.TypeExpr.EQ;
6 | import static org.xcsp.common.Types.TypeExpr.GE;
7 | import static org.xcsp.common.Types.TypeExpr.GT;
8 | import static org.xcsp.common.Types.TypeExpr.IN;
9 | import static org.xcsp.common.Types.TypeExpr.LE;
10 | import static org.xcsp.common.Types.TypeExpr.LONG;
11 | import static org.xcsp.common.Types.TypeExpr.LT;
12 | import static org.xcsp.common.Types.TypeExpr.MAX;
13 | import static org.xcsp.common.Types.TypeExpr.MIN;
14 | import static org.xcsp.common.Types.TypeExpr.MUL;
15 | import static org.xcsp.common.Types.TypeExpr.NE;
16 | import static org.xcsp.common.Types.TypeExpr.NEG;
17 | import static org.xcsp.common.Types.TypeExpr.NOT;
18 | import static org.xcsp.common.Types.TypeExpr.NOTIN;
19 | import static org.xcsp.common.Types.TypeExpr.SET;
20 | import static org.xcsp.common.Types.TypeExpr.SPECIAL;
21 | import static org.xcsp.common.Types.TypeExpr.SQR;
22 | import static org.xcsp.common.Types.TypeExpr.SUB;
23 | import static org.xcsp.common.Types.TypeExpr.VAR;
24 | import static org.xcsp.common.predicates.XNode.node;
25 | import static org.xcsp.common.predicates.XNode.specialLeaf;
26 |
27 | import java.util.function.BiPredicate;
28 | import java.util.stream.IntStream;
29 | import java.util.stream.Stream;
30 |
31 | import org.xcsp.common.IVar;
32 |
33 | /**
34 | * This interface is used to test if a specified (source) tree matches a predefined target tree. Some kind of abstraction can be used by means of special nodes.
35 | *
36 | * @author Christophe Lecoutre
37 | *
38 | */
39 | public interface MatcherInterface {
40 |
41 | enum AbstractOperation {
42 | ariop, relop, setop, unalop, symop; // logop
43 | }
44 |
45 | XNodeLeaf any = specialLeaf("any");
46 | XNodeLeaf anyc = specialLeaf("anyc"); // any under condition
47 | XNodeLeaf var = specialLeaf("var");
48 | XNodeLeaf val = specialLeaf("val");
49 | XNodeLeaf varOrVal = specialLeaf("var-or-val");
50 | XNodeLeaf any_add_val = specialLeaf("any-add-val");
51 | XNodeLeaf var_add_val = specialLeaf("var-add-val");
52 | XNodeLeaf add_lastval = specialLeaf("add-lastval");
53 | XNodeLeaf sub = specialLeaf("sub");
54 | XNodeLeaf not = specialLeaf("not");
55 | XNodeLeaf set_vals = specialLeaf("set-vals");
56 | XNodeLeaf min_vars = specialLeaf("min-vars");
57 | XNodeLeaf max_vars = specialLeaf("max-vars");
58 | XNodeLeaf logic_vars = specialLeaf("logic-vars");
59 | XNodeLeaf add_vars = specialLeaf("add-vars");
60 | XNodeLeaf mul_vars = specialLeaf("mul-vars");
61 | XNodeLeaf add_varOrVals = specialLeaf("add-varOrVals");
62 | XNodeLeaf sub_varOrVals = specialLeaf("sub-varOrVals");
63 | XNodeLeaf addOrSub_varOrVals = specialLeaf("addOrSub-varOrVals");
64 | XNodeLeaf add_varsOrTerms = specialLeaf("add-mul-vals");
65 | XNodeLeaf add_mulVars = specialLeaf("add-mul-vars");
66 | XNodeLeaf add_varsOrTerms_valEnding = specialLeaf("add-mul-vals2");
67 | XNodeLeaf or = specialLeaf("or");
68 |
69 | XNodeLeaf trivial0 = specialLeaf("trivial0");
70 | XNodeLeaf trivial1 = specialLeaf("trivial1");
71 |
72 | Matcher x_add_k = new Matcher(node(ADD, var, val));
73 | Matcher x_sub_k = new Matcher(node(SUB, var, val));
74 | Matcher x_mul_k = new Matcher(node(MUL, var, val));
75 | Matcher x_mul_y = new Matcher(node(MUL, var, var));
76 | Matcher k_mul_x = new Matcher(node(MUL, val, var)); // used in some other contexts (when non canonized forms)
77 |
78 | Matcher x_ne_k = new Matcher(node(NE, var, val));
79 | Matcher x_eq_k = new Matcher(node(EQ, var, val));
80 | Matcher x_lt_k = new Matcher(node(LT, var, val));
81 | Matcher x_le_k = new Matcher(node(LE, var, val));
82 | Matcher k_le_x = new Matcher(node(LE, val, var));
83 | Matcher x_ge_k = new Matcher(node(GE, var, val));
84 | Matcher x_gt_k = new Matcher(node(GT, var, val));
85 |
86 | Matcher x_ne_y = new Matcher(node(NE, var, var));
87 |
88 | /**
89 | * Returns the target tree, which may possibly involve some form of abstraction by means of special nodes.
90 | *
91 | * @return the target tree
92 | */
93 | abstract XNode target();
94 |
95 | /**
96 | * Returns {@code true} if the specified node (considered at the specified level/depth) is valid with respect to the target tree when assuming that the
97 | * corresponding node in the target tree is a special node.
98 | *
99 | * @param node
100 | * a (source) node
101 | * @param level
102 | * the level/depth associated with the node
103 | * @return {@code true} if the specified source node is valid with respect to a corresponding special node in the target tree
104 | */
105 | abstract boolean validForSpecialTargetNode(XNode extends IVar> node, int level);
106 |
107 | /**
108 | * Returns {@code true} if the specified source tree matches the specified target tree (at the specified level).
109 | *
110 | * @param source
111 | * the source (sub-)tree
112 | * @param target
113 | * the target (sub-)tree
114 | * @param level
115 | * the level/depth for the comparison
116 | * @return {@code true} if the specified source tree matches the specified target tree
117 | */
118 | default boolean matching(XNode extends IVar> source, XNode target, int level) {
119 | // System.out.println("matching " + source.type + " vs " + target);
120 | if (target == any) // any node (i.e., full abstract node) => everything matches
121 | return true;
122 | if (target == anyc) // any node under condition (the difference with SPECIAL only, is that sons are not considered recursively)
123 | return validForSpecialTargetNode(source, level);
124 | if (target == var) {
125 | // System.out.println("var " + (source.type == VAR));
126 | return source.type == VAR;
127 | }
128 | if (target == val) {
129 | // System.out.println("val " + (source.type == LONG));
130 | return source.type == LONG;
131 | }
132 | if (target == varOrVal)
133 | return source.type == VAR || source.type == LONG;
134 | if (target == any_add_val)
135 | return source.type == ADD && source.sons.length == 2 && source.sons[1].type == LONG;
136 | if (target == var_add_val)
137 | return source.type == ADD && source.sons.length == 2 && source.sons[0].type == VAR && source.sons[1].type == LONG;
138 | if (target == add_lastval)
139 | return source.type == ADD && source.sons.length > 2 && source.sons[source.sons.length - 1].type == LONG;
140 | if (target == sub)
141 | return source.type == SUB;
142 | if (target == not)
143 | return source.type == NOT;
144 | if (target == set_vals) // abstract set => we control that source is either an empty set or a set built on only longs
145 | return source.type == SET && (source instanceof XNodeLeaf || Stream.of(source.sons).allMatch(s -> s.type == LONG));
146 | if (target == min_vars) // abstract min => we control that source is a min built on only variables
147 | return source.type == MIN && source.sons.length >= 2 && Stream.of(source.sons).allMatch(s -> s.type == VAR);
148 | if (target == max_vars) // abstract max => we control that source is a max built on only variables
149 | return source.type == MAX && source.sons.length >= 2 && Stream.of(source.sons).allMatch(s -> s.type == VAR);
150 | if (target == logic_vars)
151 | return source.type.isLogicalOperator() && source.sons.length >= 2 && Stream.of(source.sons).allMatch(s -> s.type == VAR);
152 | if (target == add_vars)
153 | return source.type == ADD && source.sons.length >= 2 && Stream.of(source.sons).allMatch(s -> s.type == VAR);
154 | if (target == mul_vars)
155 | return source.type == MUL && source.sons.length >= 2 && Stream.of(source.sons).allMatch(s -> s.type == VAR);
156 | if (target == add_varOrVals)
157 | return source.type == ADD && source.sons.length >= 2 && Stream.of(source.sons).allMatch(s -> s.type == VAR || s.type == LONG);
158 | if (target == sub_varOrVals)
159 | return source.type == SUB && source.sons.length == 2 && Stream.of(source.sons).allMatch(s -> s.type == VAR || s.type == LONG);
160 | if (target == addOrSub_varOrVals)
161 | return (source.type == ADD || source.type == SUB) && source.sons.length >= 2
162 | && Stream.of(source.sons).allMatch(s -> s.type == VAR || s.type == LONG);
163 | if (target == add_varsOrTerms)
164 | return source.type == ADD && source.sons.length >= 2 && Stream.of(source.sons).allMatch(s -> s.type == VAR || x_mul_k.matches(s));
165 | if (target == add_mulVars)
166 | return source.type == ADD && source.sons.length >= 2 && Stream.of(source.sons).allMatch(s -> x_mul_y.matches(s));
167 | if (target == add_varsOrTerms_valEnding)
168 | return source.type == ADD && source.sons.length > 2 && source.sons[source.sons.length - 1].type == LONG
169 | && IntStream.range(0, source.sons.length - 1).allMatch(i -> source.sons[i].type == VAR || x_mul_k.matches(source.sons[i]));
170 |
171 | if (target == trivial0) // other trivial cases equivalent to 0 (false)?
172 | return source.type.oneOf(NE, LT, GT) && source.sons.length == 2 && source.sons[0].type == VAR && source.sons[1].type == VAR
173 | && ((XNodeLeaf>) source.sons[0]).value == ((XNodeLeaf>) source.sons[1]).value;
174 |
175 | if (target == trivial1) // other trivial cases equivalent to 1 (true)?
176 | return source.type.oneOf(EQ, LE, GE) && source.sons.length == 2 && source.sons[0].type == VAR && source.sons[1].type == VAR
177 | && ((XNodeLeaf>) source.sons[0]).value == ((XNodeLeaf>) source.sons[1]).value;
178 |
179 | if (target instanceof XNodeLeaf != source instanceof XNodeLeaf)
180 | return false;
181 | if (target.type != SPECIAL && target.type != source.type)
182 | return false;
183 | if (target.type == SPECIAL) {
184 | if (target instanceof XNodeParentSpecial) {
185 | AbstractOperation ao = AbstractOperation.valueOf(((XNodeParentSpecial>) target).specialName);
186 | if (ao == AbstractOperation.ariop)
187 | if (!source.type.isArithmeticOperator())
188 | return false;
189 | if (ao == AbstractOperation.relop)
190 | if (!source.type.isRelationalOperator())
191 | return false;
192 | if (ao == AbstractOperation.setop)
193 | if (!source.type.oneOf(IN, NOTIN))
194 | return false;
195 | if (ao == AbstractOperation.unalop)
196 | if (!source.type.oneOf(ABS, NEG, SQR, NOT))
197 | return false;
198 | if (ao == AbstractOperation.symop)
199 | if (!source.type.oneOf(EQ, NE))
200 | return false;
201 | } else if (!validForSpecialTargetNode(source, level))
202 | return false;
203 |
204 | }
205 | if (target instanceof XNodeLeaf)
206 | return true; // it seems that we have no more control to do
207 | return target.sons.length == source.sons.length
208 | && IntStream.range(0, target.sons.length).allMatch(i -> matching(source.sons[i], target.sons[i], level + 1));
209 | }
210 |
211 | /**
212 | * Returns {@code true} if the predefined target tree matches the specified (source) tree.
213 | *
214 | * @param tree
215 | * a tree
216 | * @return {@code true} if the predefined target tree matches the specified (source) tree
217 | */
218 | default boolean matches(XNode extends IVar> tree) {
219 | return matching(tree, target(), 0);
220 | }
221 |
222 | /**
223 | * This class allows us to perform matching tests between trees.
224 | */
225 | final class Matcher implements MatcherInterface {
226 | private final XNode target;
227 |
228 | private final BiPredicate, Integer> p;
229 |
230 | @Override
231 | public XNode target() {
232 | return target;
233 | }
234 |
235 | /**
236 | * Builds a {@code Matcher} object with the specified target tree.
237 | *
238 | * @param target
239 | * the target tree
240 | * @param p
241 | * a predicate used for special nodes in some occasions
242 | */
243 | public Matcher(XNode target, BiPredicate, Integer> p) {
244 | this.target = target;
245 | this.p = p;
246 | }
247 |
248 | /**
249 | * Builds a {@code Matcher} object with the specified target tree.
250 | *
251 | * @param target
252 | * the target tree
253 | */
254 | public Matcher(XNode target) {
255 | this(target, null); // (node, level) -> true); // (level == 0 && node.type.isRelationalOperator()) || (level == 1 &&
256 | // node.type.isArithmeticOperator()));
257 | }
258 |
259 | @Override
260 | public boolean validForSpecialTargetNode(XNode extends IVar> node, int level) {
261 | return p == null || p.test(node, level);
262 | }
263 | }
264 |
265 | }
--------------------------------------------------------------------------------
/src/main/java/org/xcsp/common/predicates/XNodeLeaf.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016 XCSP3 Team (contact@xcsp.org)
3 | *
4 | * 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
5 | * the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
6 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7 | *
8 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9 | *
10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
11 | * 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
12 | * 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.
13 | */
14 | package org.xcsp.common.predicates;
15 |
16 | import java.util.LinkedList;
17 | import java.util.List;
18 | import java.util.Map;
19 | import java.util.function.Function;
20 | import java.util.function.Predicate;
21 | import java.util.stream.IntStream;
22 |
23 | import org.xcsp.common.IVar;
24 | import org.xcsp.common.Types.TypeExpr;
25 | import org.xcsp.common.Utilities;
26 | import org.xcsp.common.domains.Values.Decimal;
27 |
28 | /**
29 | * The class used for representing a leaf node in a syntactic tree.
30 | *
31 | * @author Christophe Lecoutre
32 | */
33 | public final class XNodeLeaf extends XNode {
34 |
35 | @Override
36 | public boolean equals(Object obj) {
37 | if (!(obj instanceof XNodeLeaf))
38 | return false;
39 | return type == ((XNodeLeaf>) obj).type && value.equals(((XNodeLeaf>) obj).value);
40 | }
41 |
42 | @Override
43 | public int compareTo(XNode obj) {
44 | if (type != obj.type)
45 | return Integer.compare(type.ordinal(), obj.type.ordinal());
46 | XNodeLeaf leaf = (XNodeLeaf) obj;
47 | if (type == TypeExpr.VAR)
48 | return ((IVar) value).id().compareTo(((IVar) leaf.value).id());
49 | if (type == TypeExpr.PAR || type == TypeExpr.LONG)
50 | return Long.compare((long) value, (long) leaf.value);
51 | if (type == TypeExpr.SYMBOL)
52 | return ((String) value).compareTo((String) leaf.value);
53 | if (type == TypeExpr.SET)
54 | return 0; // because two empty sets
55 | throw new RuntimeException("Currently, this statement should not be reached.");
56 | }
57 |
58 | /** The (parsed) value of the node. it may be a variable, a decimal, a long, a parameter, a symbol or null for an empty set. */
59 | public Object value;
60 |
61 | public Object oldValue;
62 |
63 | /** Builds a leaf node for a syntactic tree, with the specified type and the specified value. */
64 | public XNodeLeaf(TypeExpr type, Object... value) {
65 | super(type, null);
66 | this.value = value[0];
67 | if (value.length > 1)
68 | this.oldValue = value[1]; // ugly way of saving the old value when trees are transformed
69 | Utilities.control(type.arityMin == 0 && type.arityMax == 0 || (type == TypeExpr.SET || type == TypeExpr.SPECIAL), "Pb with this node " + type);
70 | }
71 |
72 | @Override
73 | public int size() {
74 | return 1;
75 | }
76 |
77 | @Override
78 | public int maxParameterNumber() {
79 | return type == TypeExpr.PAR ? ((Long) value).intValue() : -1; // recall that %... is not possible in predicates
80 | }
81 |
82 | @Override
83 | public XNode canonization() {
84 | return new XNodeLeaf(type, value); // we return a similar object
85 | }
86 |
87 | @Override
88 | public XNode abstraction(List