Skip to content

Commit 3b546cd

Browse files
committed
Merge pull request anfelbar#7 from carealejo/master
getIntVar, Linear, Full getIntVarArgs
2 parents 7216ee4 + c0de4ce commit 3b546cd

32 files changed

+1447
-4
lines changed

CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
cmake_minimum_required(VERSION 2.8)
22
project(MOZARTVM)
33

4+
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake-support")
5+
option(BUILD_CSS "Builds the constraint subsystem" Yes)
6+
47
include(ExternalProject)
58
set(ep_base "${CMAKE_BINARY_DIR}/externals")
69
set_property(DIRECTORY PROPERTY "EP_BASE" ${ep_base})
@@ -17,6 +20,14 @@ set(GTEST_BUILD_DIR ${DEFAULT_GTEST_BUILD_DIR} CACHE PATH "Path to GTest build")
1720
set(MOZART_GENERATOR_FLAGS "${DEFAULT_MOZART_GENERATOR_FLAGS}" CACHE STRING
1821
"Additional flags for the generator parser (clang)")
1922

23+
if (BUILD_CSS)
24+
include(Gecode)
25+
set(MOZART_GENERATOR_FLAGS
26+
"-DVM_HAS_CSS=1" "-I${GECODE_INCLUDES}" ${MOZART_GENERATOR_FLAGS})
27+
include_directories("${GECODE_INCLUDES}")
28+
message(STATUS "Generator flags: ${MOZART_GENERATOR_FLAGS}")
29+
endif()
30+
2031
add_subdirectory(generator)
2132

2233
set(CMAKE_CXX_FLAGS "-Wall -std=c++0x ${CMAKE_CXX_FLAGS}")

boostenv/main/CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
2525
set(MOZART_GENERATOR_FLAGS "-I/usr/lib/c++/v1")
2626
endif()
2727

28+
if(BUILD_CSS)
29+
list(APPEND MOZART_GENERATOR_FLAGS "-DVM_HAS_CSS=1" "-I${GECODE_INCLUDES}")
30+
include_directories(${GECODE_INCLUDES})
31+
add_definitions("-DVM_HAS_CSS=1")
32+
endif()
33+
2834
# Mozart VM library
2935

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

8288
# Boost environment library
8389

90+
if(BUILD_CSS)
91+
add_definitions(-DVM_HAS_CSS=1)
92+
include_directories(${GECODE_INCLUDES})
93+
endif()
94+
8495
add_library(mozartvmboost boostenv.cc boostenvmodules.cc)
8596
add_dependencies(mozartvmboost genboostsources)

cmake-support/Gecode.cmake

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
set(DEFAULT_GECODE_INSTALL_DIR "${ep_base}/Install/gecode")
2+
set(GECODE_INSTALL_DIR ${DEFAULT_GECODE_INSTALL_DIR} CACHE PATH
3+
"Path to Gecode installation")
4+
5+
set(GECODE_VERSION 3.7.3)
6+
7+
if("${GECODE_INSTALL_DIR}" STREQUAL "${DEFAULT_GECODE_INSTALL_DIR}" AND
8+
NOT EXISTS "${GECODE_INSTALL_DIR}/lib/gecode/kernel.hh")
9+
10+
message(STATUS "Gecode version ${GECODE_VERSION} will be fetch and built")
11+
set(GECODE_SRC_DIR "${ep_base}/Source/gecode")
12+
set(GECODE_BUILD_DIR "${ep_base}/Build/gecode")
13+
14+
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
15+
set(CMAKE_CXX_FLAGS "-stdlib=libc++ ${CMAKE_CXX_FLAGS}")
16+
endif()
17+
18+
separate_arguments(GECODE_CONFIGURE_ARGS UNIX_COMMAND
19+
"CC=${CMAKE_C_COMPILER}
20+
CXX=${CMAKE_CXX_COMPILER}
21+
CXX_FLAGS=${CMAKE_CXX_FLAGS}
22+
CPPFLAGS=${CMAKE_C_FLAGS}
23+
--enable-static
24+
--disable-shared
25+
--prefix=${GECODE_INSTALL_DIR}
26+
--libdir=${GECODE_INSTALL_DIR}/lib
27+
--disable-gist
28+
--disable-flatzinc
29+
--disable-examples
30+
--disable-qt
31+
--disable-driver
32+
--disable-minimodel"
33+
)
34+
35+
ExternalProject_Add(
36+
gecode
37+
URL http://www.gecode.org/download/gecode-${GECODE_VERSION}.tar.gz
38+
SOURCE_DIR ${GECODE_SRC_DIR}
39+
BINARY_DIR ${GECODE_BUILD_DIR}
40+
UPDATE_COMMAND ""
41+
PATCH_COMMAND ""
42+
CONFIGURE_COMMAND ${GECODE_SRC_DIR}/configure
43+
${GECODE_CONFIGURE_ARGS}
44+
BUILD_COMMAND make -j 4
45+
INSTALL_COMMAND make install
46+
)
47+
endif()
48+
49+
link_directories(${GECODE_INSTALL_DIR}/lib)
50+
set(GECODE_LIBRARIES
51+
gecodesearch
52+
gecodeset
53+
gecodeint
54+
gecodekernel
55+
gecodesupport
56+
)
57+
set(GECODE_INCLUDES ${GECODE_INSTALL_DIR}/include)
58+
59+
foreach(GECODE_LIB ${GECODE_LIBRARIES})
60+
add_library(${GECODE_LIB} STATIC IMPORTED)
61+
set_property(TARGET ${GECODE_LIB} PROPERTY
62+
IMPORTED_LOCATION ${GECODE_INSTALL_DIR}/lib/lib${GECODE_LIB}.a)
63+
endforeach()

vm/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ if("${GTEST_SRC_DIR}" STREQUAL "${DEFAULT_GTEST_SRC_DIR}" AND
2020
TEST_COMMAND ""
2121
)
2222
endif()
23+
2324
add_subdirectory(main)
2425
add_subdirectory(test)

vm/main/CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,19 @@ add_custom_target(gensources
5454
DEPENDS mozart.gen
5555
VERBATIM)
5656

57+
if(BUILD_CSS)
58+
add_definitions(-DVM_HAS_CSS=1)
59+
include_directories(${GECODE_INCLUDES})
60+
endif()
61+
5762
# Build the library
5863

5964
add_library(mozartvm emulate.cc memmanager.cc gcollect.cc
6065
unify.cc sclone.cc vm.cc coredatatypes.cc coders.cc properties.cc
6166
coremodules.cc bootunpickler.cc serializer.cc)
6267
add_dependencies(mozartvm gensources)
68+
69+
if(BUILD_CSS)
70+
add_dependencies(mozartvm ${GECODE_LIBRARIES})
71+
target_link_libraries(mozartvm ${GECODE_LIBRARIES})
72+
endif()

vm/main/coreatoms-decl.hh

+50
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,56 @@ struct CoreAtoms {
8686
atom_t spaceAltRange;
8787
atom_t spaceMerged;
8888
atom_t indexOutOfBounds;
89+
90+
// Constraint programming
91+
// Integer relation types
92+
atom_t irt_eq;
93+
atom_t irt_nq;
94+
atom_t irt_lq;
95+
atom_t irt_le;
96+
atom_t irt_gq;
97+
atom_t irt_gr;
98+
99+
// Integer consistency levels
100+
atom_t icl_val;
101+
atom_t icl_bnd;
102+
atom_t icl_dom;
103+
atom_t icl_def;
104+
105+
// Integer IntVarBranch types
106+
atom_t int_var_none;
107+
atom_t int_var_rnd;
108+
atom_t int_var_degree_min;
109+
atom_t int_var_degree_max;
110+
atom_t int_var_afc_min;
111+
atom_t int_var_min_min;
112+
atom_t int_var_min_max;
113+
atom_t int_var_max_min;
114+
atom_t int_var_max_max;
115+
atom_t int_var_size_min;
116+
atom_t int_var_size_max;
117+
atom_t int_var_size_degree_min;
118+
atom_t int_var_size_degree_max;
119+
atom_t int_var_size_afc_min;
120+
atom_t int_var_size_afc_max;
121+
atom_t int_var_regret_min_min;
122+
atom_t int_var_regret_min_max;
123+
atom_t int_var_regret_max_min;
124+
atom_t int_var_regret_max_max;
125+
126+
// Integer IntValBranch types
127+
atom_t int_val_min;
128+
atom_t int_val_med;
129+
atom_t int_val_max;
130+
atom_t int_val_rad;
131+
atom_t int_val_split_min;
132+
atom_t int_val_split_max;
133+
atom_t int_val_range_min;
134+
atom_t int_val_range_max;
135+
atom_t int_values_min;
136+
atom_t int_values_max;
137+
138+
89139
};
90140

91141
}

vm/main/coreatoms.hh

+44
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,50 @@ void CoreAtoms::initialize(VM vm, AtomTable& atomTable) {
7474
spaceAltRange = atomTable.get(vm, MOZART_STR("spaceAltRange"));
7575
spaceMerged = atomTable.get(vm, MOZART_STR("spaceMerged"));
7676
indexOutOfBounds = atomTable.get(vm, MOZART_STR("indexOutOfBounds"));
77+
78+
irt_eq = atomTable.get(vm, MOZART_STR("IRT_EQ"));
79+
irt_nq = atomTable.get(vm, MOZART_STR("IRT_NQ"));
80+
irt_lq = atomTable.get(vm, MOZART_STR("IRT_LQ"));
81+
irt_le = atomTable.get(vm, MOZART_STR("IRT_LE"));
82+
irt_gq = atomTable.get(vm, MOZART_STR("IRT_GQ"));
83+
irt_gr = atomTable.get(vm, MOZART_STR("IRT_GR"));
84+
85+
icl_val = atomTable.get(vm, MOZART_STR("ICL_VAL"));
86+
icl_bnd = atomTable.get(vm, MOZART_STR("ICL_BND"));
87+
icl_dom = atomTable.get(vm, MOZART_STR("ICL_DOM"));
88+
icl_def = atomTable.get(vm, MOZART_STR("ICL_DEF"));
89+
90+
int_var_none = atomTable.get(vm, MOZART_STR("INT_VAR_NONE"));
91+
int_var_rnd = atomTable.get(vm, MOZART_STR("INT_VAR_RND"));
92+
int_var_degree_min = atomTable.get(vm, MOZART_STR("INT_VAR_DEGREE_MIN"));
93+
int_var_degree_max = atomTable.get(vm, MOZART_STR("INT_VAR_DEGREE_MAX"));
94+
int_var_afc_min = atomTable.get(vm, MOZART_STR("INT_VAR_AFC_MIN"));
95+
int_var_min_min = atomTable.get(vm, MOZART_STR("INT_VAR_MIN_MIN"));
96+
int_var_min_max = atomTable.get(vm, MOZART_STR("INT_VAR_MIN_MAX"));
97+
int_var_max_min = atomTable.get(vm, MOZART_STR("INT_VAR_MAX_MIN"));
98+
int_var_max_max = atomTable.get(vm, MOZART_STR("INT_VAR_MAX_MAX"));
99+
int_var_size_min = atomTable.get(vm, MOZART_STR("INT_VAR_SIZE_MIN"));
100+
int_var_size_max = atomTable.get(vm, MOZART_STR("INT_VAR_SIZE_MAX"));
101+
int_var_size_degree_min = atomTable.get(vm, MOZART_STR("INT_VAR_SIZE_DEGREE_MIN"));
102+
int_var_size_degree_max = atomTable.get(vm, MOZART_STR("INT_VAR_SIZE_DEGREE_MAX"));
103+
int_var_size_afc_min = atomTable.get(vm, MOZART_STR("INT_VAR_SIZE_AFC_MIN"));
104+
int_var_size_afc_max = atomTable.get(vm, MOZART_STR("INT_VAR_SIZE_AFC_MAX"));
105+
int_var_regret_min_min = atomTable.get(vm, MOZART_STR("INT_VAR_REGRET_MIN_MIN"));
106+
int_var_regret_min_max = atomTable.get(vm, MOZART_STR("INT_VAR_REGRET_MIN_MAX"));
107+
int_var_regret_max_min = atomTable.get(vm, MOZART_STR("INT_VAR_REGRET_MAX_MIN"));
108+
int_var_regret_max_max = atomTable.get(vm, MOZART_STR("INT_VAR_REGRET_MAX_MAX"));
109+
110+
int_val_min = atomTable.get(vm, MOZART_STR("INT_VAL_MIN"));
111+
int_val_med = atomTable.get(vm, MOZART_STR("INT_VAL_MED"));
112+
int_val_max = atomTable.get(vm, MOZART_STR("INT_VAL_MAX"));
113+
int_val_rad = atomTable.get(vm, MOZART_STR("INT_VAL_RND"));
114+
int_val_split_min = atomTable.get(vm, MOZART_STR("INT_VAL_SPLIT_MIN"));
115+
int_val_split_max = atomTable.get(vm, MOZART_STR("INT_VAL_SPLIT_MAX"));
116+
int_val_range_min = atomTable.get(vm, MOZART_STR("INT_VAL_RANGE_MIN"));
117+
int_val_range_max = atomTable.get(vm, MOZART_STR("INT_VAL_RANGE_MAX"));
118+
int_values_min = atomTable.get(vm, MOZART_STR("INT_VALUES_MIN"));
119+
int_values_max = atomTable.get(vm, MOZART_STR("INT_VALUES_MAX"));
120+
77121
}
78122

79123
}

vm/main/coredatatypes-decl.hh

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,9 @@
5656
#include "string-decl.hh"
5757
#include "unit-decl.hh"
5858
#include "variables-decl.hh"
59-
59+
//#ifdef VM_HAS_CSS
60+
#include "cstintvar-decl.hh"
61+
#include "cstsetvar-decl.hh"
62+
#include "cstboolvar-decl.hh"
63+
//#endif
6064
#endif // __COREDATATYPES_DECL_H

vm/main/coredatatypes.hh

+5
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,10 @@
5656
#include "string.hh"
5757
#include "unit.hh"
5858
#include "variables.hh"
59+
//#ifdef VM_HAS_CSS
60+
#include "cstintvar.hh"
61+
#include "cstsetvar.hh"
62+
#include "cstboolvar.hh"
63+
//#endif
5964

6065
#endif // __COREDATATYPES_H

vm/main/coreinterfaces-decl.hh

+101
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,17 @@ struct Interface<SpaceLike>:
568568
void killSpace(RichNode self, VM vm) {
569569
raiseTypeError(vm, MOZART_STR("Space"), self);
570570
}
571+
572+
void injectSpace(RichNode self, VM vm, RichNode callable) {
573+
raiseTypeError(vm, MOZART_STR("Space"), self);
574+
}
575+
576+
#ifdef VM_HAS_CSS
577+
void info(RichNode self, VM vm) {
578+
raiseTypeError(vm, MOZART_STR("Space"), self);
579+
}
580+
#endif
581+
571582
};
572583

573584
class ThreadLike;
@@ -669,6 +680,96 @@ struct Interface<StringLike>:
669680
}
670681
};
671682

683+
#ifdef VM_HAS_CSS
684+
class ConstraintVar;
685+
template <>
686+
struct Interface<ConstraintVar>:
687+
ImplementedBy<SmallInt, CstIntVar>,
688+
NoAutoReflectiveCalls {
689+
690+
bool assigned(RichNode self, VM vm) {
691+
raiseTypeError(vm, MOZART_STR("ConstraintVar"), self);
692+
}
693+
};
694+
695+
class IntVarLike;
696+
template<>
697+
struct Interface<IntVarLike>:
698+
ImplementedBy<SmallInt, CstIntVar>,
699+
NoAutoReflectiveCalls {
700+
701+
bool isIntVarLike(RichNode self, VM vm) {
702+
return false;
703+
}
704+
705+
Gecode::IntVar& intVar(RichNode self, VM vm) {
706+
raiseTypeError(vm, MOZART_STR("IntVarLike"), self);
707+
}
708+
709+
UnstableNode min(RichNode self, VM vm) {
710+
raiseTypeError(vm, MOZART_STR("IntVarLike"), self);
711+
}
712+
713+
UnstableNode max(RichNode self, VM vm) {
714+
raiseTypeError(vm, MOZART_STR("IntVarLike"), self);
715+
}
716+
717+
UnstableNode value(RichNode self, VM vm) {
718+
raiseTypeError(vm, MOZART_STR("IntVarLike"), self);
719+
}
720+
721+
UnstableNode isIn(RichNode self, VM vm, RichNode right) {
722+
raiseTypeError(vm, MOZART_STR("IntVarLike"), self);
723+
}
724+
};
725+
726+
class SetVarLike;
727+
template<>
728+
struct Interface<SetVarLike>:
729+
ImplementedBy<CstSetVar>,
730+
NoAutoReflectiveCalls {
731+
732+
bool isSetVarLike(RichNode self, VM vm) {
733+
return false;
734+
}
735+
736+
Gecode::SetVar& setVar(RichNode self, VM vm) {
737+
raiseTypeError(vm, MOZART_STR("SetVarLike"), self);
738+
}
739+
};
740+
741+
class BoolVarLike;
742+
template<>
743+
struct Interface<BoolVarLike>:
744+
ImplementedBy<CstBoolVar>,
745+
NoAutoReflectiveCalls {
746+
747+
bool isBoolVarLike(RichNode self, VM vm) {
748+
return false;
749+
}
750+
751+
Gecode::BoolVar& boolVar(RichNode self, VM vm) {
752+
raiseTypeError(vm, MOZART_STR("BoolVarLike"), self);
753+
}
754+
};
755+
756+
class ConstraintSpace;
757+
template<>
758+
struct Interface<ConstraintSpace>:
759+
ImplementedBy<ReifiedSpace>,
760+
NoAutoReflectiveCalls {
761+
762+
bool isConstraintSpace(RichNode self, VM vm) {
763+
return false;
764+
}
765+
766+
GecodeSpace& constraintSpace(RichNode self, VM vm) {
767+
raiseTypeError(vm, MOZART_STR("ConstraintSpace"), self);
768+
}
769+
};
770+
771+
#endif
772+
672773
}
673774

674775
#endif // __COREINTERFACES_DECL_H

0 commit comments

Comments
 (0)