more work on fz2 constraints
This commit is contained in:
@@ -981,11 +981,17 @@ $(LIB_DIR)/$(LIBPREFIX)fz2.$(DYNAMIC_LIB_SUFFIX): $(FLATZINC2_LIB_OBJS)
|
||||
$(OBJ_DIR)/flatzinc2/fz.$O:$(SRC_DIR)/flatzinc2/fz.cc $(SRC_DIR)/flatzinc2/model.h $(SRC_DIR)/flatzinc2/solver.h
|
||||
$(CCC) $(CFLAGS) -c $(SRC_DIR)$Sflatzinc2$Sfz.cc $(OBJ_OUT)$(OBJ_DIR)$Sflatzinc2$Sfz.$O
|
||||
|
||||
fz2 : $(BIN_DIR)/fz2$E
|
||||
$(OBJ_DIR)/flatzinc2/parser_main.$O:$(SRC_DIR)/flatzinc2/parser_main.cc $(SRC_DIR)/flatzinc2/model.h $(SRC_DIR)/flatzinc2/solver.h
|
||||
$(CCC) $(CFLAGS) -c $(SRC_DIR)$Sflatzinc2$Sparser_main.cc $(OBJ_OUT)$(OBJ_DIR)$Sflatzinc2$Sparser_main.$O
|
||||
|
||||
fz2 : $(BIN_DIR)/fz2$E $(BIN_DIR)/parser_main$E
|
||||
|
||||
$(BIN_DIR)/fz2$E: $(OBJ_DIR)/flatzinc2/fz.$O $(DYNAMIC_FLATZINC2_DEPS)
|
||||
$(CCC) $(CFLAGS) $(OBJ_DIR)$Sflatzinc2$Sfz.$O $(STATIC_FZ) $(DYNAMIC_FLATZINC2_LNK) $(DYNAMIC_LD_FLAGS) $(EXE_OUT)$(BIN_DIR)$Sfz2$E
|
||||
|
||||
$(BIN_DIR)/parser_main$E: $(OBJ_DIR)/flatzinc2/parser_main.$O $(DYNAMIC_FLATZINC2_DEPS)
|
||||
$(CCC) $(CFLAGS) $(OBJ_DIR)$Sflatzinc2$Sparser_main.$O $(STATIC_FZ) $(DYNAMIC_FLATZINC2_LNK) $(DYNAMIC_LD_FLAGS) $(EXE_OUT)$(BIN_DIR)$Sparser_main$E
|
||||
|
||||
# Flow and linear assignment cpp
|
||||
|
||||
$(OBJ_DIR)/linear_assignment_api.$O:$(EX_DIR)/cpp/linear_assignment_api.cc
|
||||
|
||||
@@ -250,12 +250,14 @@ std::string FzIntegerVariable::DebugString() const {
|
||||
|
||||
std::string FzConstraint::DebugString() const {
|
||||
const std::string strong = strong_propagation ? ", strong propagation" : "";
|
||||
const std::string trivially_true = is_trivially_true ? "[trivially true]"
|
||||
: "";
|
||||
const std::string target = target_var != nullptr
|
||||
? StringPrintf(" => %s", target_var->name.c_str())
|
||||
: "";
|
||||
return StringPrintf("%s([%s]%s)%s", type.c_str(),
|
||||
return StringPrintf("%s([%s]%s)%s %s", type.c_str(),
|
||||
JoinDebugString(arguments, ", ").c_str(), strong.c_str(),
|
||||
target.c_str());
|
||||
target.c_str(), trivially_true.c_str());
|
||||
}
|
||||
|
||||
// ----- FzAnnotation -----
|
||||
|
||||
@@ -20,29 +20,32 @@
|
||||
#include "base/commandlineflags.h"
|
||||
#include "flatzinc2/model.h"
|
||||
#include "flatzinc2/parser.h"
|
||||
#include "flatzinc2/presolve.h"
|
||||
|
||||
DEFINE_string(file, "", "Input file in the flatzinc format");
|
||||
DEFINE_string(file, "", "Input file in the flatzinc format.");
|
||||
DEFINE_bool(presolve, false, "Presolve loaded file.");
|
||||
|
||||
namespace operations_research {
|
||||
void ParseFile(const string& filename, bool presolve) {
|
||||
std::string problem_name(filename);
|
||||
problem_name.resize(problem_name.size() - 4);
|
||||
size_t found = problem_name.find_last_of("/\\");
|
||||
if (found != std::string::npos) {
|
||||
problem_name = problem_name.substr(found + 1);
|
||||
}
|
||||
FzModel model(problem_name);
|
||||
CHECK(ParseFlatzincFile(filename, &model));
|
||||
if (presolve) {
|
||||
FzPresolver presolve;
|
||||
presolve.Run(&model);
|
||||
}
|
||||
LOG(INFO) << model.DebugString();
|
||||
}
|
||||
} // namespace operations_research
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
FLAGS_log_prefix = false;
|
||||
InitGoogle(
|
||||
"Parses a flatzinc .fzn file and prints it in human-readable "
|
||||
"format",
|
||||
&argc, &argv, /*remove_flags=*/true);
|
||||
std::string problem_name = FLAGS_file;
|
||||
// Remove the .fzn extension.
|
||||
QCHECK(problem_name.size() > 4 &&
|
||||
problem_name.substr(problem_name.size() - 4) == ".fzn")
|
||||
<< "Please supply a valid data file name (ending with .fzn) with --file.";
|
||||
problem_name.resize(problem_name.size() - 4);
|
||||
// Remove the leading path if present.
|
||||
size_t basename_offset = problem_name.find_last_of("/\\");
|
||||
if (basename_offset != std::string::npos) {
|
||||
problem_name = problem_name.substr(basename_offset + 1);
|
||||
}
|
||||
// Parse the model and print it out.
|
||||
operations_research::FzModel model(problem_name);
|
||||
operations_research::ParseFlatzincFile(FLAGS_file, &model);
|
||||
LOG(INFO) << model.DebugString();
|
||||
google::ParseCommandLineFlags(&argc, &argv, /*remove_flags=*/true);
|
||||
operations_research::ParseFile(FLAGS_file, FLAGS_presolve);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -48,14 +48,19 @@ bool FzPresolver::PresolveBool2Int(FzConstraint* input) {
|
||||
bool FzPresolver::PresolveIntEq(FzConstraint* input) {
|
||||
if (input->arguments[0].type == FzArgument::INT_VAR_REF) {
|
||||
if (input->arguments[1].type == FzArgument::INT_VAR_REF) {
|
||||
MarkVariablesAsEquivalent(input->arguments[0].variable,
|
||||
input->arguments[1].variable);
|
||||
if (input->arguments[0].variable->defining_constraint == nullptr ||
|
||||
input->arguments[1].variable->defining_constraint == nullptr) {
|
||||
MarkVariablesAsEquivalent(input->arguments[0].variable,
|
||||
input->arguments[1].variable);
|
||||
MarkAsTriviallyTrue(input);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
const int64 value = input->arguments[1].integer_value;
|
||||
input->arguments[0].variable->domain.ReduceDomain(value, value);
|
||||
MarkAsTriviallyTrue(input);
|
||||
return true;
|
||||
}
|
||||
MarkAsTriviallyTrue(input);
|
||||
return true;
|
||||
} else { // Arg0 is an integer value.
|
||||
const int64 value = input->arguments[0].integer_value;
|
||||
if (input->arguments[1].type == FzArgument::INT_VAR_REF) {
|
||||
@@ -73,6 +78,7 @@ bool FzPresolver::PresolveIntEq(FzConstraint* input) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FzPresolver::PresolveOneConstraint(FzConstraint* ct) {
|
||||
|
||||
Reference in New Issue
Block a user