From cda53edf0e8db761bbec8bfa52889433da09c467 Mon Sep 17 00:00:00 2001 From: "lperron@google.com" Date: Thu, 19 Jul 2012 05:22:46 +0000 Subject: [PATCH] more work --- examples/cpp/jobshop_next.cc | 7 +++++-- src/constraint_solver/resource.cc | 19 ++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/examples/cpp/jobshop_next.cc b/examples/cpp/jobshop_next.cc index 90a7c1d0f2..3bd0c93ca2 100644 --- a/examples/cpp/jobshop_next.cc +++ b/examples/cpp/jobshop_next.cc @@ -54,6 +54,7 @@ DEFINE_string( "list of \" \"\n" "note: jobs with one task are not supported"); DEFINE_int32(time_limit_in_ms, 0, "Time limit in ms, 0 means no limit."); +DEFINE_bool(full_debug, false, ""); namespace operations_research { void Jobshop(const JobShopData& data) { @@ -172,8 +173,10 @@ void Jobshop(const JobShopData& data) { // Search. solver.NewSearch(main_phase, search_log, objective_monitor, limit); while (solver.NextSolution()) { - for (int i = 0; i < machine_count; ++i) { - all_machines_[i]->FullDebug(); + if (FLAGS_full_debug) { + for (int i = 0; i < machine_count; ++i) { + all_machines_[i]->FullDebug(); + } } } solver.EndSearch(); diff --git a/src/constraint_solver/resource.cc b/src/constraint_solver/resource.cc index 067fc11e1a..06f656e7a9 100644 --- a/src/constraint_solver/resource.cc +++ b/src/constraint_solver/resource.cc @@ -815,16 +815,21 @@ class FullDisjunctiveConstraint : public DisjunctiveConstraint { virtual void BuildNextModel() { Solver* const s = solver(); const string ct_name = name(); - s->MakeIntVarArray(size_ + 1, 0, size_ + 1, ct_name + "_nexts", &nexts_); + s->MakeIntVarArray(size_ + 1, 1, size_ + 1, ct_name + "_nexts", &nexts_); int64 horizon = 0; for (int i = 0; i < size_; ++i) { horizon = std::max(horizon, intervals_[i]->EndMax()); } actives_.resize(size_ + 1); - actives_[0] = s->MakeBoolVar("DepotActive"); + std::vector performed(size_); for (int i = 0; i < size_; ++i) { actives_[i + 1] = intervals_[i]->PerformedExpr()->Var(); + performed[i] = actives_[i + 1]; } + actives_[0] = s->MakeIsDifferentCstVar(nexts_[0], Zero()); + s->AddConstraint(s->MakeMaxEquality(performed, actives_[0])); + // actives_[0]->SetValue(true); + // All Diff s->AddConstraint(s->MakeAllDifferent(nexts_)); @@ -850,11 +855,11 @@ class FullDisjunctiveConstraint : public DisjunctiveConstraint { for (int64 i = 0; i < size_; ++i) { IntVar* const fixed_transit = s->MakeElement(durations_, nexts_[i])->Var(); - // IntVar* const slack_var = s->MakeIntVar(0, horizon, "slack"); - // time_transits_[i + 1] = s->MakeSum(slack_var, fixed_transit)->Var(); - time_transits_[i + 1] = fixed_transit; - // time_transits_[i + 1]->SetRange(0, horizon); - // time_slacks_[i + 1] = slack_var; + IntVar* const slack_var = s->MakeIntVar(0, horizon, "slack"); + time_transits_[i + 1] = s->MakeSum(slack_var, fixed_transit)->Var(); + //time_transits_[i + 1] = fixed_transit; + time_transits_[i + 1]->SetRange(0, horizon); + time_slacks_[i + 1] = slack_var; time_cumuls_[i + 1] = s->MakeElement(start_times_, nexts_[i])->Var(); } time_cumuls_[size_ + 1] = s->MakeIntVar(0, horizon, ct_name + "_ect");