Skip to content

Commit

Permalink
Merge branch 'release/3.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
richoux committed Sep 26, 2023
2 parents 920a811 + 364d499 commit 03f7eab
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
37 changes: 35 additions & 2 deletions include/solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>> &domains )
{
for( auto& constraint : _model.constraints )
{
auto var_index = constraint->_variables_index;
if( var_index.size() == 1 )
{
std::vector<int> 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
Expand Down Expand Up @@ -869,12 +892,17 @@ 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<int>( _model.variables.size() ); ++variable_id )
{
_matrix_var_ctr[ variable_id ] = std::vector<int>();
for( int constraint_id = 0; constraint_id < static_cast<int>( _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 );

for( int value : domains[0] )
{
_model.variables[0].set_value( value );
Expand All @@ -891,7 +919,12 @@ namespace ghost
solutions_exist = true;
for( int i = 1 ; i < static_cast<int>( 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 );
}
}
Expand Down

0 comments on commit 03f7eab

Please sign in to comment.