| 2008 | } |
| 2009 | |
| 2010 | bool |
| 2011 | FlatZincSpace::slave(const MetaInfo& mi) { |
| 2012 | if (mi.type() == MetaInfo::RESTART) { |
| 2013 | if (restart_data.initialized() && restart_data().mark_complete) { |
| 2014 | // Fail the space |
| 2015 | this->fail(); |
| 2016 | // Return true to signal we are in the global search space |
| 2017 | return true; |
| 2018 | } |
| 2019 | |
| 2020 | bool ret = false; |
| 2021 | if (on_restart_iv.size() > 0) { |
| 2022 | int base = 0; |
| 2023 | |
| 2024 | // Assign the sol_int values (use lb if no solution is known) |
| 2025 | const FlatZincSpace* last = static_cast<const FlatZincSpace*>(mi.last()); |
| 2026 | assert(last == nullptr || last->on_restart_iv.size() == restart_data().on_restart_iv_sol); |
| 2027 | for (int i = 0; i < restart_data().on_restart_iv_sol; ++i) { |
| 2028 | IntVar& outVar = on_restart_iv[base + restart_data().on_restart_iv_sol + i]; |
| 2029 | int solVal = (last != nullptr) ? last->on_restart_iv[i].val() : on_restart_iv[base + i].min(); |
| 2030 | rel(*this, outVar, IRT_EQ, solVal); |
| 2031 | } |
| 2032 | base += restart_data().on_restart_iv_sol * 2; |
| 2033 | |
| 2034 | // Assign last_val_int values |
| 2035 | for (size_t i = 0; i < restart_data().last_val_int.size(); ++i) { |
| 2036 | rel(*this, on_restart_iv[base + i], IRT_EQ, restart_data().last_val_int[i]); |
| 2037 | } |
| 2038 | base += restart_data().last_val_int.size(); |
| 2039 | |
| 2040 | // Assign uniform_int random values |
| 2041 | for (size_t i = 0; i < restart_data().uniform_range_int.size(); ++i) { |
| 2042 | const auto& range = restart_data().uniform_range_int[i]; |
| 2043 | const int rndVal = range.first + _random(static_cast<unsigned int>(range.second - range.first)); |
| 2044 | rel(*this, on_restart_iv[base + i], IRT_EQ, rndVal); |
| 2045 | } |
| 2046 | base += restart_data().uniform_range_int.size(); |
| 2047 | |
| 2048 | // Set the status value |
| 2049 | if (restart_data().on_restart_status) { |
| 2050 | assert(base == on_restart_iv.size() - 1); |
| 2051 | IntVar& restart_status = on_restart_iv[base]; |
| 2052 | switch(mi.reason()) { |
| 2053 | case MetaInfo::RR_INIT: |
| 2054 | assert(!mi.last()); |
| 2055 | rel(*this, restart_status, IRT_EQ, 1); // 1: START |
| 2056 | break; |
| 2057 | case MetaInfo::RR_SOL: |
| 2058 | assert(mi.solution() > 0); |
| 2059 | rel(*this, restart_status, IRT_EQ, 4); // 4: SAT |
| 2060 | break; |
| 2061 | case MetaInfo::RR_CMPL: |
| 2062 | rel(*this, restart_status, IRT_EQ, 3); // 3: UNSAT |
| 2063 | break; |
| 2064 | default: |
| 2065 | assert(mi.reason() == MetaInfo::RR_LIM); |
| 2066 | rel(*this, restart_status, IRT_EQ, 2); // 2: UNKNOWN |
| 2067 | break; |