Skip to content

Commit

Permalink
Merge pull request anfelbar#8 from carealejo/master
Browse files Browse the repository at this point in the history
Distinct2
  • Loading branch information
anfelbar committed Apr 9, 2013
2 parents 7216ee4 + 1a7cce7 commit d722a6d
Show file tree
Hide file tree
Showing 32 changed files with 1,483 additions and 4 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
cmake_minimum_required(VERSION 2.8)
project(MOZARTVM)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake-support")
option(BUILD_CSS "Builds the constraint subsystem" Yes)

include(ExternalProject)
set(ep_base "${CMAKE_BINARY_DIR}/externals")
set_property(DIRECTORY PROPERTY "EP_BASE" ${ep_base})
Expand All @@ -17,6 +20,14 @@ set(GTEST_BUILD_DIR ${DEFAULT_GTEST_BUILD_DIR} CACHE PATH "Path to GTest build")
set(MOZART_GENERATOR_FLAGS "${DEFAULT_MOZART_GENERATOR_FLAGS}" CACHE STRING
"Additional flags for the generator parser (clang)")

if (BUILD_CSS)
include(Gecode)
set(MOZART_GENERATOR_FLAGS
"-DVM_HAS_CSS=1" "-I${GECODE_INCLUDES}" ${MOZART_GENERATOR_FLAGS})
include_directories("${GECODE_INCLUDES}")
message(STATUS "Generator flags: ${MOZART_GENERATOR_FLAGS}")
endif()

add_subdirectory(generator)

set(CMAKE_CXX_FLAGS "-Wall -std=c++0x ${CMAKE_CXX_FLAGS}")
Expand Down
11 changes: 11 additions & 0 deletions boostenv/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MOZART_GENERATOR_FLAGS "-I/usr/lib/c++/v1")
endif()

if(BUILD_CSS)
list(APPEND MOZART_GENERATOR_FLAGS "-DVM_HAS_CSS=1" "-I${GECODE_INCLUDES}")
include_directories(${GECODE_INCLUDES})
add_definitions("-DVM_HAS_CSS=1")
endif()

# Mozart VM library

include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../vm/main"
Expand Down Expand Up @@ -81,5 +87,10 @@ add_custom_target(genboostsources

# Boost environment library

if(BUILD_CSS)
add_definitions(-DVM_HAS_CSS=1)
include_directories(${GECODE_INCLUDES})
endif()

add_library(mozartvmboost boostenv.cc boostenvmodules.cc)
add_dependencies(mozartvmboost genboostsources)
63 changes: 63 additions & 0 deletions cmake-support/Gecode.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
set(DEFAULT_GECODE_INSTALL_DIR "${ep_base}/Install/gecode")
set(GECODE_INSTALL_DIR ${DEFAULT_GECODE_INSTALL_DIR} CACHE PATH
"Path to Gecode installation")

set(GECODE_VERSION 3.7.3)

if("${GECODE_INSTALL_DIR}" STREQUAL "${DEFAULT_GECODE_INSTALL_DIR}" AND
NOT EXISTS "${GECODE_INSTALL_DIR}/lib/gecode/kernel.hh")

message(STATUS "Gecode version ${GECODE_VERSION} will be fetch and built")
set(GECODE_SRC_DIR "${ep_base}/Source/gecode")
set(GECODE_BUILD_DIR "${ep_base}/Build/gecode")

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_CXX_FLAGS "-stdlib=libc++ ${CMAKE_CXX_FLAGS}")
endif()

separate_arguments(GECODE_CONFIGURE_ARGS UNIX_COMMAND
"CC=${CMAKE_C_COMPILER}
CXX=${CMAKE_CXX_COMPILER}
CXX_FLAGS=${CMAKE_CXX_FLAGS}
CPPFLAGS=${CMAKE_C_FLAGS}
--enable-static
--disable-shared
--prefix=${GECODE_INSTALL_DIR}
--libdir=${GECODE_INSTALL_DIR}/lib
--disable-gist
--disable-flatzinc
--disable-examples
--disable-qt
--disable-driver
--disable-minimodel"
)

ExternalProject_Add(
gecode
URL http://www.gecode.org/download/gecode-${GECODE_VERSION}.tar.gz
SOURCE_DIR ${GECODE_SRC_DIR}
BINARY_DIR ${GECODE_BUILD_DIR}
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ${GECODE_SRC_DIR}/configure
${GECODE_CONFIGURE_ARGS}
BUILD_COMMAND make -j 4
INSTALL_COMMAND make install
)
endif()

link_directories(${GECODE_INSTALL_DIR}/lib)
set(GECODE_LIBRARIES
gecodesearch
gecodeset
gecodeint
gecodekernel
gecodesupport
)
set(GECODE_INCLUDES ${GECODE_INSTALL_DIR}/include)

foreach(GECODE_LIB ${GECODE_LIBRARIES})
add_library(${GECODE_LIB} STATIC IMPORTED)
set_property(TARGET ${GECODE_LIB} PROPERTY
IMPORTED_LOCATION ${GECODE_INSTALL_DIR}/lib/lib${GECODE_LIB}.a)
endforeach()
1 change: 1 addition & 0 deletions vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ if("${GTEST_SRC_DIR}" STREQUAL "${DEFAULT_GTEST_SRC_DIR}" AND
TEST_COMMAND ""
)
endif()

add_subdirectory(main)
add_subdirectory(test)
10 changes: 10 additions & 0 deletions vm/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,19 @@ add_custom_target(gensources
DEPENDS mozart.gen
VERBATIM)

if(BUILD_CSS)
add_definitions(-DVM_HAS_CSS=1)
include_directories(${GECODE_INCLUDES})
endif()

# Build the library

add_library(mozartvm emulate.cc memmanager.cc gcollect.cc
unify.cc sclone.cc vm.cc coredatatypes.cc coders.cc properties.cc
coremodules.cc bootunpickler.cc serializer.cc)
add_dependencies(mozartvm gensources)

if(BUILD_CSS)
add_dependencies(mozartvm ${GECODE_LIBRARIES})
target_link_libraries(mozartvm ${GECODE_LIBRARIES})
endif()
50 changes: 50 additions & 0 deletions vm/main/coreatoms-decl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,56 @@ struct CoreAtoms {
atom_t spaceAltRange;
atom_t spaceMerged;
atom_t indexOutOfBounds;

// Constraint programming
// Integer relation types
atom_t irt_eq;
atom_t irt_nq;
atom_t irt_lq;
atom_t irt_le;
atom_t irt_gq;
atom_t irt_gr;

// Integer consistency levels
atom_t icl_val;
atom_t icl_bnd;
atom_t icl_dom;
atom_t icl_def;

// Integer IntVarBranch types
atom_t int_var_none;
atom_t int_var_rnd;
atom_t int_var_degree_min;
atom_t int_var_degree_max;
atom_t int_var_afc_min;
atom_t int_var_min_min;
atom_t int_var_min_max;
atom_t int_var_max_min;
atom_t int_var_max_max;
atom_t int_var_size_min;
atom_t int_var_size_max;
atom_t int_var_size_degree_min;
atom_t int_var_size_degree_max;
atom_t int_var_size_afc_min;
atom_t int_var_size_afc_max;
atom_t int_var_regret_min_min;
atom_t int_var_regret_min_max;
atom_t int_var_regret_max_min;
atom_t int_var_regret_max_max;

// Integer IntValBranch types
atom_t int_val_min;
atom_t int_val_med;
atom_t int_val_max;
atom_t int_val_rad;
atom_t int_val_split_min;
atom_t int_val_split_max;
atom_t int_val_range_min;
atom_t int_val_range_max;
atom_t int_values_min;
atom_t int_values_max;


};

}
Expand Down
44 changes: 44 additions & 0 deletions vm/main/coreatoms.hh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,50 @@ void CoreAtoms::initialize(VM vm, AtomTable& atomTable) {
spaceAltRange = atomTable.get(vm, MOZART_STR("spaceAltRange"));
spaceMerged = atomTable.get(vm, MOZART_STR("spaceMerged"));
indexOutOfBounds = atomTable.get(vm, MOZART_STR("indexOutOfBounds"));

irt_eq = atomTable.get(vm, MOZART_STR("IRT_EQ"));
irt_nq = atomTable.get(vm, MOZART_STR("IRT_NQ"));
irt_lq = atomTable.get(vm, MOZART_STR("IRT_LQ"));
irt_le = atomTable.get(vm, MOZART_STR("IRT_LE"));
irt_gq = atomTable.get(vm, MOZART_STR("IRT_GQ"));
irt_gr = atomTable.get(vm, MOZART_STR("IRT_GR"));

icl_val = atomTable.get(vm, MOZART_STR("ICL_VAL"));
icl_bnd = atomTable.get(vm, MOZART_STR("ICL_BND"));
icl_dom = atomTable.get(vm, MOZART_STR("ICL_DOM"));
icl_def = atomTable.get(vm, MOZART_STR("ICL_DEF"));

int_var_none = atomTable.get(vm, MOZART_STR("INT_VAR_NONE"));
int_var_rnd = atomTable.get(vm, MOZART_STR("INT_VAR_RND"));
int_var_degree_min = atomTable.get(vm, MOZART_STR("INT_VAR_DEGREE_MIN"));
int_var_degree_max = atomTable.get(vm, MOZART_STR("INT_VAR_DEGREE_MAX"));
int_var_afc_min = atomTable.get(vm, MOZART_STR("INT_VAR_AFC_MIN"));
int_var_min_min = atomTable.get(vm, MOZART_STR("INT_VAR_MIN_MIN"));
int_var_min_max = atomTable.get(vm, MOZART_STR("INT_VAR_MIN_MAX"));
int_var_max_min = atomTable.get(vm, MOZART_STR("INT_VAR_MAX_MIN"));
int_var_max_max = atomTable.get(vm, MOZART_STR("INT_VAR_MAX_MAX"));
int_var_size_min = atomTable.get(vm, MOZART_STR("INT_VAR_SIZE_MIN"));
int_var_size_max = atomTable.get(vm, MOZART_STR("INT_VAR_SIZE_MAX"));
int_var_size_degree_min = atomTable.get(vm, MOZART_STR("INT_VAR_SIZE_DEGREE_MIN"));
int_var_size_degree_max = atomTable.get(vm, MOZART_STR("INT_VAR_SIZE_DEGREE_MAX"));
int_var_size_afc_min = atomTable.get(vm, MOZART_STR("INT_VAR_SIZE_AFC_MIN"));
int_var_size_afc_max = atomTable.get(vm, MOZART_STR("INT_VAR_SIZE_AFC_MAX"));
int_var_regret_min_min = atomTable.get(vm, MOZART_STR("INT_VAR_REGRET_MIN_MIN"));
int_var_regret_min_max = atomTable.get(vm, MOZART_STR("INT_VAR_REGRET_MIN_MAX"));
int_var_regret_max_min = atomTable.get(vm, MOZART_STR("INT_VAR_REGRET_MAX_MIN"));
int_var_regret_max_max = atomTable.get(vm, MOZART_STR("INT_VAR_REGRET_MAX_MAX"));

int_val_min = atomTable.get(vm, MOZART_STR("INT_VAL_MIN"));
int_val_med = atomTable.get(vm, MOZART_STR("INT_VAL_MED"));
int_val_max = atomTable.get(vm, MOZART_STR("INT_VAL_MAX"));
int_val_rad = atomTable.get(vm, MOZART_STR("INT_VAL_RND"));
int_val_split_min = atomTable.get(vm, MOZART_STR("INT_VAL_SPLIT_MIN"));
int_val_split_max = atomTable.get(vm, MOZART_STR("INT_VAL_SPLIT_MAX"));
int_val_range_min = atomTable.get(vm, MOZART_STR("INT_VAL_RANGE_MIN"));
int_val_range_max = atomTable.get(vm, MOZART_STR("INT_VAL_RANGE_MAX"));
int_values_min = atomTable.get(vm, MOZART_STR("INT_VALUES_MIN"));
int_values_max = atomTable.get(vm, MOZART_STR("INT_VALUES_MAX"));

}

}
Expand Down
6 changes: 5 additions & 1 deletion vm/main/coredatatypes-decl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,9 @@
#include "string-decl.hh"
#include "unit-decl.hh"
#include "variables-decl.hh"

//#ifdef VM_HAS_CSS
#include "cstintvar-decl.hh"
#include "cstsetvar-decl.hh"
#include "cstboolvar-decl.hh"
//#endif
#endif // __COREDATATYPES_DECL_H
5 changes: 5 additions & 0 deletions vm/main/coredatatypes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,10 @@
#include "string.hh"
#include "unit.hh"
#include "variables.hh"
//#ifdef VM_HAS_CSS
#include "cstintvar.hh"
#include "cstsetvar.hh"
#include "cstboolvar.hh"
//#endif

#endif // __COREDATATYPES_H
101 changes: 101 additions & 0 deletions vm/main/coreinterfaces-decl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,17 @@ struct Interface<SpaceLike>:
void killSpace(RichNode self, VM vm) {
raiseTypeError(vm, MOZART_STR("Space"), self);
}

void injectSpace(RichNode self, VM vm, RichNode callable) {
raiseTypeError(vm, MOZART_STR("Space"), self);
}

#ifdef VM_HAS_CSS
void info(RichNode self, VM vm) {
raiseTypeError(vm, MOZART_STR("Space"), self);
}
#endif

};

class ThreadLike;
Expand Down Expand Up @@ -669,6 +680,96 @@ struct Interface<StringLike>:
}
};

#ifdef VM_HAS_CSS
class ConstraintVar;
template <>
struct Interface<ConstraintVar>:
ImplementedBy<SmallInt, CstIntVar>,
NoAutoReflectiveCalls {

bool assigned(RichNode self, VM vm) {
raiseTypeError(vm, MOZART_STR("ConstraintVar"), self);
}
};

class IntVarLike;
template<>
struct Interface<IntVarLike>:
ImplementedBy<SmallInt, CstIntVar>,
NoAutoReflectiveCalls {

bool isIntVarLike(RichNode self, VM vm) {
return false;
}

Gecode::IntVar& intVar(RichNode self, VM vm) {
raiseTypeError(vm, MOZART_STR("IntVarLike"), self);
}

UnstableNode min(RichNode self, VM vm) {
raiseTypeError(vm, MOZART_STR("IntVarLike"), self);
}

UnstableNode max(RichNode self, VM vm) {
raiseTypeError(vm, MOZART_STR("IntVarLike"), self);
}

UnstableNode value(RichNode self, VM vm) {
raiseTypeError(vm, MOZART_STR("IntVarLike"), self);
}

UnstableNode isIn(RichNode self, VM vm, RichNode right) {
raiseTypeError(vm, MOZART_STR("IntVarLike"), self);
}
};

class SetVarLike;
template<>
struct Interface<SetVarLike>:
ImplementedBy<CstSetVar>,
NoAutoReflectiveCalls {

bool isSetVarLike(RichNode self, VM vm) {
return false;
}

Gecode::SetVar& setVar(RichNode self, VM vm) {
raiseTypeError(vm, MOZART_STR("SetVarLike"), self);
}
};

class BoolVarLike;
template<>
struct Interface<BoolVarLike>:
ImplementedBy<CstBoolVar>,
NoAutoReflectiveCalls {

bool isBoolVarLike(RichNode self, VM vm) {
return false;
}

Gecode::BoolVar& boolVar(RichNode self, VM vm) {
raiseTypeError(vm, MOZART_STR("BoolVarLike"), self);
}
};

class ConstraintSpace;
template<>
struct Interface<ConstraintSpace>:
ImplementedBy<ReifiedSpace>,
NoAutoReflectiveCalls {

bool isConstraintSpace(RichNode self, VM vm) {
return false;
}

GecodeSpace& constraintSpace(RichNode self, VM vm) {
raiseTypeError(vm, MOZART_STR("ConstraintSpace"), self);
}
};

#endif

}

#endif // __COREINTERFACES_DECL_H
Loading

0 comments on commit d722a6d

Please sign in to comment.