Skip to content
Open
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
main/cosoco
main/cosoco.*

# the clangd cache
.cache
# the build folder
build
# the default cmake makefile
Makefile

.vscode
Testing



# instances
Expand All @@ -12,6 +22,8 @@ cmake_install.cmake
cmake-build-debug
CMakeFiles
CMakeCache.txt
cosoco-test*_include.cmake
CTestTestfile.cmake

#
lib
Expand Down
109 changes: 66 additions & 43 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
cmake_minimum_required(VERSION 3.3)
cmake_minimum_required(VERSION 3.12)
#set(CMAKE_C_COMPILER "gcc-7")
#set(CMAKE_CXX_COMPILER "g++-7")
project(cosoco)

# Check if the 'no-xcsp3' option is enabled
option(NO_XCSP3 "Disable XCSP3 support" OFF)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/main")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The definition of those path are now set to the build.sh file. That way, we can safely build the different versions in different folders without having to fear that one might contaminate the other.

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib)
# define some c++ flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-parentheses -Wall -O3 -Wno-unused-label")
if(NO_XCSP3)
#turn warning into errors only when we are not using XCSP3 parser
#as the errors might come from the dependencies (libxml2 or XCSP3-Parser)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wnon-virtual-dtor")
endif()

# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wno-parentheses -Wall -O3 -Wno-unused-label")

include_directories(/usr/local/opt/libxml2/include/libxml2/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

find_package(LibXml2 REQUIRED)
include_directories(${LIBXML2_INCLUDE_DIRS})
if(NOT NO_XCSP3)
#if we're not using xcsp, don't include libxml2
include_directories(/usr/local/opt/libxml2/include/libxml2/)
find_package(LibXml2 REQUIRED)
include_directories(${LIBXML2_INCLUDE_DIRS})
endif()

file(GLOB_RECURSE Cosoco_SOURCES
${PROJECT_SOURCE_DIR}/constraints/*.cc
Expand All @@ -27,52 +37,65 @@ file(GLOB_RECURSE Cosoco_SOURCES
${PROJECT_SOURCE_DIR}/utils/*.cc
)

file(GLOB_RECURSE Cosoco_HEADERS
${PROJECT_SOURCE_DIR}/constraints/*.h
${PROJECT_SOURCE_DIR}/core/*.h
${PROJECT_SOURCE_DIR}/mtl/*.h
${PROJECT_SOURCE_DIR}/main/*.h
${PROJECT_SOURCE_DIR}/optimizer/*.h
${PROJECT_SOURCE_DIR}/problems/*.h
${PROJECT_SOURCE_DIR}/solver/*.h
${PROJECT_SOURCE_DIR}/utils/*.h
)

set(LIBRARY_NAME libcosoco)


file(GLOB_RECURSE Cosoco_HEADERS "./*.h")

set(Cosoco_INCLUDE_DIRS "")

foreach (_headerFile ${Cosoco_HEADERS})
get_filename_component(_dir ${_headerFile} PATH)
list(APPEND Cosoco_INCLUDE_DIRS ${_dir})
endforeach ()

list(REMOVE_DUPLICATES Cosoco_INCLUDE_DIRS)

include_directories(
${Cosoco_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/../XCSP3-CPP-Parser/include/
)


add_library(${LIBRARY_NAME} STATIC ${Cosoco_SOURCES}
solver/utils/Profiling.cc)

if(NOT NO_XCSP3)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../XCSP3-CPP-Parser/include/
)

link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../XCSP3-CPP-Parser/lib)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../XCSP3-CPP-Parser/lib)
target_compile_definitions(${LIBRARY_NAME} PRIVATE USE_XCSP3)
endif()

set_target_properties(${LIBRARY_NAME} PROPERTIES OUTPUT_NAME "cosoco")


link_libraries(xcsp3parser)
add_executable(cosoco main/Main.cc
mtl/Matrix.h)
target_link_libraries(cosoco ${LIBRARY_NAME})
target_link_libraries(cosoco ${LIBXML2_LIBRARIES})


target_include_directories(${LIBRARY_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

#define the executable
if(NOT NO_XCSP3)
link_libraries(xcsp3parser)
add_executable(cosoco main/Main.cc
mtl/Matrix.h)
target_compile_definitions(cosoco PRIVATE USE_XCSP3)
target_link_libraries(cosoco ${LIBRARY_NAME})
target_link_libraries(cosoco ${LIBXML2_LIBRARIES})


target_include_directories(${LIBRARY_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
endif()


#tests
# Find Google Test (if not present, tests will not be compiled)
find_package(GTest)

if(GTEST_FOUND)
# Add test source files
file(GLOB_RECURSE Cosoco_TESTS
${PROJECT_SOURCE_DIR}/test/*.cc
)
#define the test executable and its dependencies
add_executable(cosoco-test ${Cosoco_TESTS})
target_link_libraries(cosoco-test GTest::gtest_main)
target_link_libraries(cosoco-test ${LIBRARY_NAME})
if(NOT NO_XCSP3)
target_include_directories(cosoco-test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../XCSP3-CPP-Parser/include/)
target_include_directories(cosoco-test PRIVATE ${LIBXML2_INCLUDE_DIRS})
target_link_libraries(cosoco-test ${LIBXML2_LIBRARIES})
target_link_libraries(cosoco-test xcsp3parser)
target_link_directories(cosoco-test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../XCSP3-CPP-Parser/lib)
endif()

enable_testing()
# Add a test target
include(GoogleTest)
gtest_discover_tests(cosoco-test)
endif()
3 changes: 3 additions & 0 deletions build-lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cmake -DNO_XCSP3=ON -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" .
#cmake -DCMAKE_BUILD_TYPE=Debug -G "Unix Makefiles" .
cmake --build . --target libcosoco -- -j 8
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cd ../XCSP3-CPP-Parser
./build.sh
cd ../cosoco/
cmake -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" .
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_RUNTIME_OUTPUT_DIRECTORY="`pwd`/main" -DCMAKE_LIBRARY_OUTPUT_DIRECTORY="`pwd`/lib" -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY="`pwd`/lib" -G "Unix Makefiles" .
#cmake -DCMAKE_BUILD_TYPE=Debug -G "Unix Makefiles" .
cmake --build . --target cosoco -- -j 8
14 changes: 10 additions & 4 deletions constraints/Constraint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

#include <utility>

#ifdef USE_XCSP3
#include "XCSP3Tree.h"
#include "mtl/Map.h"
#include "solver/utils/FactoryConstraints.h"
#include "utils/Utils.h"
#else
#include "utils/Options.h"
#endif /* #ifdef USE_XCSP3 */

#include "core/Problem.h"

using namespace std;
using namespace Cosoco;
Expand Down Expand Up @@ -154,6 +158,7 @@ void Constraint::extractConstraintTupleFromInterpretation(const vec<int> &interp
}
}

#ifdef USE_XCSP3

void createTuples(int posx, vec<Variable *> &scope, XCSP3Core::Tree *tree, vec<vec<int>> &conflicts, vec<vec<int>> &supports,
std::map<string, int> &tuple) {
Expand All @@ -162,16 +167,16 @@ void createTuples(int posx, vec<Variable *> &scope, XCSP3Core::Tree *tree, vec<v

for(int i = 0; i < x->domain.maxSize(); i++) {
tuple[x->_name] = x->domain.toVal(i);
if(posx == scope.size() - 2 && tree->root->type == OEQ && tree->root->parameters[1]->type == OVAR) {
auto *nv = dynamic_cast<NodeVariable *>(tree->root->parameters[1]);
if(posx == scope.size() - 2 && tree->root->type == XCSP3Core::OEQ && tree->root->parameters[1]->type == XCSP3Core::OVAR) {
auto *nv = dynamic_cast<XCSP3Core::NodeVariable *>(tree->root->parameters[1]);
if(nodeContainsVar(tree->root->parameters[0], nv->var) == false) {
// we have expr = var
// we evaluate the expression and put the value in support
int eval = tree->root->parameters[0]->evaluate(tuple);
if(scope.last()->containsValue(eval)) {
supports.push();
tuple[scope.last()->_name] = eval;
assert(tuple.size() == scope.size());
assert(tuple.size() == (size_t)scope.size());
for(auto &x : scope) supports.last().push(tuple[x->_name]);
}
continue;
Expand Down Expand Up @@ -207,6 +212,7 @@ void Constraint::toExtensionConstraint(XCSP3Core::Tree *tree, vec<Variable *> &s
}
}

#endif /* USE_XCSP3 */

// Display
void Constraint::display(bool allDetails) {
Expand Down
22 changes: 15 additions & 7 deletions constraints/Constraint.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
#ifndef CONSTRAINT_H
#define CONSTRAINT_H

#include <iostream>
#include <string>

#include "XCSP3Tree.h"
#include "core/Problem.h"
#include "core/Variable.h"
#include "mtl/SparseSet.h"
#include "mtl/SparseSetOfVariables.h"
#include "mtl/Vec.h"


#define NOTINSCOPE -1

#ifdef USE_XCSP3
#include <vector>
namespace XCSP3Core {
class Tree;
}
#endif

namespace Cosoco {

enum State { CONSISTENT, INCONSISTENT, UNDEF };
Expand Down Expand Up @@ -49,8 +54,9 @@ class Constraint {
// Constructors and delayed initialisation
Constraint(Problem &p, std::string n, vec<Variable *> &vars);
Constraint(Problem &p, std::string n); // For global constraints, the scope is managed by themselves
bool scopeIsOk(); // is the scope is correctly defined?
virtual bool isCorrectlyDefined(); // is the constraint is correctly defined?
virtual ~Constraint() = default;
bool scopeIsOk(); // is the scope is correctly defined?
virtual bool isCorrectlyDefined(); // is the constraint is correctly defined?
void addToScope(vec<Variable *> &vars);
void addToScope(Variable *x);

Expand Down Expand Up @@ -88,8 +94,10 @@ class Constraint {
// Display
virtual void display(bool allDetails = false);
virtual void attachSolver(Solver *s);
static void toExtensionConstraint(XCSP3Core::Tree *tree, vec<Variable *> &scope, std::vector<std::vector<int> > &tuples,
bool &isSupport); // Extract Extensional . Return nullptr if too many tuples
#ifdef USE_XCSP3
static void toExtensionConstraint(XCSP3Core::Tree *tree, vec<Variable *> &scope, std::vector<std::vector<int> > &tuples,
bool &isSupport); // Extract Extensional . Return nullptr if too many tuples
#endif

protected:
// All this part simplify scope initialisation
Expand Down
6 changes: 3 additions & 3 deletions constraints/extensions/CompactTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#define COSOCO_COMPACTTABLE_H


#include "Extension.h"
#include "ObserverDecision.h"
#include "SparseSetMultiLevel.h"
#include "constraints/extensions/Extension.h"
#include "mtl/SparseSetMultiLevel.h"
#include "solver/observers/ObserverDecision.h"
#define BITSET unsigned long long
#define SIZEW (8 * sizeof(BITSET))
#define BIT_ALL_ONE 0xFFFFFFFFFFFFFFFF
Expand Down
4 changes: 2 additions & 2 deletions constraints/extensions/Extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#define EXTENSION_H


#include "Matrix.h"
#include "XCSP3Constants.h"
#include "constraints/Constraint.h"
#include "mtl/Matrix.h"
#include "utils/Constants.h"

namespace Cosoco {
class Extension : public Constraint {
Expand Down
4 changes: 4 additions & 0 deletions constraints/extensions/MDDExtension.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "MDDExtension.h"

#ifdef USE_XCSP3

#include "constraints/extensions/structures/MDD.h"
#include "solver/Solver.h"

Expand Down Expand Up @@ -148,3 +150,5 @@ void MDDExtension::attachSolver(Solver *s) {


void MDDExtension::notifyDeleteDecision(Variable *x, int v, Solver &s) { falseTimestamp++; }

#endif /* USE_XCSP3 */
4 changes: 4 additions & 0 deletions constraints/extensions/MDDExtension.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#ifndef COSOCO_MDDEXTENSION_H
#define COSOCO_MDDEXTENSION_H

#ifdef USE_XCSP3

#include "Extension.h"
#include "solver/observers/ObserverDecision.h"
Expand Down Expand Up @@ -37,4 +39,6 @@ class MDDExtension : public Extension, ObserverDeleteDecision {
};
} // namespace Cosoco

#endif /* USE_XCSP3 */

#endif // COSOCO_MDDEXTENSION_H
2 changes: 1 addition & 1 deletion constraints/extensions/ShortSTR2.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "ShortSTR2.h"

#include "XCSP3Constants.h"
#include "mtl/Matrix.h"
#include "solver/Solver.h"
#include "utils/Constants.h"
// TODO restore lastsize when backtracking

using namespace Cosoco;
Expand Down
5 changes: 4 additions & 1 deletion constraints/extensions/structures/MDD.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "MDD.h"

#ifdef USE_XCSP3

#include <map>
#include <new>
#include <set>

#include "MDD.h"
using namespace Cosoco;


Expand Down Expand Up @@ -170,3 +171,5 @@ bool MDDNode::isRoot() const { return level == 0; }
MDDNode::MDDNode(std::string n, int _id, int lvl, int maxNbChilds) : id(_id), level(lvl), name(n) {
childs.growTo(maxNbChilds, nullptr);
}

#endif /* USE_XCSP3 */
3 changes: 3 additions & 0 deletions constraints/extensions/structures/MDD.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#ifndef COSOCO_MDD_H
#define COSOCO_MDD_H

#ifdef USE_XCSP3

#include <core/Variable.h>
#include <mtl/Vec.h>
Expand Down Expand Up @@ -47,5 +49,6 @@ class MDD {
};
} // namespace Cosoco

#endif /* USE_XCSP3 */

#endif // COSOCO_MDD_H
Loading