From f8bd6da678f093b936ac3a8aa1c56bf6fb7d8530 Mon Sep 17 00:00:00 2001 From: Florian Richoux Date: Fri, 22 Sep 2023 17:13:07 +0900 Subject: [PATCH 1/3] Fix a mistake with maximization objectives in the complete solver, and has a prefiltering for unary constraints --- include/solver.hpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/include/solver.hpp b/include/solver.hpp index ae35816e..b1eb4ced 100644 --- a/include/solver.hpp +++ b/include/solver.hpp @@ -148,6 +148,29 @@ namespace ghost Options _options; // Options for the solver (see the struct Options). + // Prefilter domains before running the AC3 algorithm, if the model contains some unary constraints + void prefiltering( std::vector< std::vector> &domains ) + { + for( auto& constraint : _model.constraints ) + { + auto var_index = constraint->_variables_index; + if( var_index.size() == 1 ) + { + std::vector values_to_remove; + int index = var_index[0]; + for( auto value : domains[index] ) + { + _model.variables[index].set_value( value ); + if( constraint->error() > 0.0 ) + values_to_remove.push_back( value ); + } + + for( int value : values_to_remove ) + domains[index].erase( std::find( domains[index].begin(), domains[index].end(), value ) ); + } + } + } + // AC3 algorithm for complete_search. This method is handling the filtering, and return filtered domains. // The vector of vector 'domains' is passed by copy on purpose. // The value of variable[ index_v ] has already been set before the call @@ -875,6 +898,8 @@ namespace ghost if( _model.constraints[ constraint_id ]->has_variable( variable_id ) ) _matrix_var_ctr[ variable_id ].push_back( constraint_id ); + prefiltering( domains ); + for( int value : domains[0] ) { _model.variables[0].set_value( value ); @@ -891,7 +916,12 @@ namespace ghost solutions_exist = true; for( int i = 1 ; i < static_cast( solution.size() ) ; ++i ) _model.variables[i].set_value( solution[i] ); - final_costs.push_back( _model.objective->cost() ); + + double cost = _model.objective->cost(); + if( _model.objective->is_maximization() ) + cost = -cost; + + final_costs.push_back( cost ); final_solutions.emplace_back( solution ); } } From dd4c3745cdf1f7d744d4798b3d4bf12e218e7d98 Mon Sep 17 00:00:00 2001 From: Florian Richoux Date: Tue, 26 Sep 2023 16:10:32 +0900 Subject: [PATCH 2/3] Change the initialization of an inner structur in Solver, to fix a bug with Clang --- include/solver.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/solver.hpp b/include/solver.hpp index b1eb4ced..56a3e4fd 100644 --- a/include/solver.hpp +++ b/include/solver.hpp @@ -892,11 +892,14 @@ namespace ghost for( auto& var : _model.variables ) domains.emplace_back( var.get_full_domain() ); - _matrix_var_ctr.reserve( _model.variables.size() ); + _matrix_var_ctr.resize( _model.variables.size() ); for( int variable_id = 0; variable_id < static_cast( _model.variables.size() ); ++variable_id ) + { + _matrix_var_ctr[ variable_id ] = std::vector(); for( int constraint_id = 0; constraint_id < static_cast( _model.constraints.size() ); ++constraint_id ) if( _model.constraints[ constraint_id ]->has_variable( variable_id ) ) _matrix_var_ctr[ variable_id ].push_back( constraint_id ); + } prefiltering( domains ); From 364d49957c4eaed23d1d501b77560c574d9e53bb Mon Sep 17 00:00:00 2001 From: Florian Richoux Date: Tue, 26 Sep 2023 16:14:39 +0900 Subject: [PATCH 3/3] Release ready --- ChangeLog.md | 6 ++++++ README.md | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 48d09b4a..89025f46 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file, since GHOST 2.0.0. +## [3.0.2] - 2023-09-26 +- Fix a mistake with maximization objectives in the complete solver, and a bug that happened with the compiler Clang. + +## [3.0.1] - 2023-09-21 +- Hotfix adding a method to call the complete solver with default options. + ## [3.0.0] - 2023-09-20 - Add a complete solver within the framework, implementing the Arc Consistency 3 algorithm and aiming to find all solutions of a problem instance. - Changed the interface `Solver::solve` -> `Solver::fast_search`, to be coherent with the new `Solver::complete_search` diff --git a/README.md b/README.md index 3599f6d4..8187d604 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![](https://github.com/richoux/GHOST/wiki/images/GHOST_banner.png) -[![3.0.0](https://img.shields.io/badge/stable-3.0.0-brightgreen.svg)](https://github.com/richoux/GHOST/releases/tag/3.0.0) +[![3.0.2](https://img.shields.io/badge/stable-3.0.2-brightgreen.svg)](https://github.com/richoux/GHOST/releases/tag/3.0.2) [![3.0.x](https://img.shields.io/badge/latest-3.0.x-f57f17.svg)](https://github.com/richoux/GHOST/tree/develop) [![Actions Status](https://github.com/richoux/GHOST/workflows/Linux/badge.svg)](https://github.com/richoux/GHOST/actions) [![Actions Status](https://github.com/richoux/GHOST/workflows/MacOS/badge.svg)](https://github.com/richoux/GHOST/actions)