Skip to content

Commit

Permalink
Polishing for 2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
richoux committed Jul 8, 2022
1 parent 624ae6e commit db91fa0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 85 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ include (InstallRequiredSystemLibraries)
set (CPACK_PACKAGE_NAME "GHOST")
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set (CPACK_PACKAGE_VERSION_MAJOR "2")
set (CPACK_PACKAGE_VERSION_MINOR "3")
set (CPACK_PACKAGE_VERSION_PATCH "1")
set (CPACK_PACKAGE_VERSION_MINOR "4")
set (CPACK_PACKAGE_VERSION_PATCH "0")
set (CPACK_PACKAGE_CONTACT "[email protected]")
set (CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
include (CPack)
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to this project will be documented in this file, since GHOST 2.0.0.

## [2.4.0] - 2022-07-08
- Error projection is now implemented following the Strategy pattern.

## [2.3.1] - 2022-06-29
- Fix an error in the AllDifferent global constraint.
- Add a constructor taking an argument std::vector<ghost::Variable> for each global constraint.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![](https://github.com/richoux/GHOST/wiki/images/GHOST_banner.png)

[![2.3.1](https://img.shields.io/badge/stable-2.3.1-brightgreen.svg)](https://github.com/richoux/GHOST/releases/tag/2.3.1)
[![2.3.x](https://img.shields.io/badge/latest-2.3.x-f57f17.svg)](https://github.com/richoux/GHOST/tree/develop)
[![2.4.0](https://img.shields.io/badge/stable-2.4.0-brightgreen.svg)](https://github.com/richoux/GHOST/releases/tag/2.4.0)
[![2.4.x](https://img.shields.io/badge/latest-2.4.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)
[![Actions Status](https://github.com/richoux/GHOST/workflows/Windows/badge.svg)](https://github.com/richoux/GHOST/actions)
Expand Down
28 changes: 2 additions & 26 deletions include/solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,20 +283,8 @@ namespace ghost
// sequential runs
if( is_sequential )
{
// SearchUnit search_unit( _model_builder.build_model(),
// _options );
SearchUnit search_unit( _model_builder.build_model(),
_options,
std::make_unique<algorithms::AdaptiveSearchVariableHeuristic>(),
std::make_unique<algorithms::AdaptiveSearchVariableCandidatesHeuristic>(),
std::make_unique<algorithms::AdaptiveSearchValueHeuristic>(),
std::make_unique<algorithms::AdaptiveSearchErrorProjection>() );
// SearchUnit search_unit( _model_builder.build_model(),
// _options,
// std::make_unique<algorithms::AntidoteSearchVariableHeuristic>(),
// std::make_unique<algorithms::AntidoteSearchVariableCandidatesHeuristic>(),
// std::make_unique<algorithms::AntidoteSearchValueHeuristic>(),
// std::make_unique<algorithms::CulpritSearchErrorProjection>() );
_options );

is_optimization = search_unit.data.is_optimization;
std::future<bool> unit_future = search_unit.solution_found.get_future();
Expand Down Expand Up @@ -333,20 +321,8 @@ namespace ghost
for( int i = 0 ; i < _options.number_threads; ++i )
{
// Instantiate one model per thread
// units.emplace_back( _model_builder.build_model(),
// _options );
units.emplace_back( _model_builder.build_model(),
_options,
std::make_unique<algorithms::AdaptiveSearchVariableHeuristic>(),
std::make_unique<algorithms::AdaptiveSearchVariableCandidatesHeuristic>(),
std::make_unique<algorithms::AdaptiveSearchValueHeuristic>(),
std::make_unique<algorithms::AdaptiveSearchErrorProjection>() );
// units.emplace_back( _model_builder.build_model(),
// _options,
// std::make_unique<algorithms::AntidoteSearchVariableHeuristic>(),
// std::make_unique<algorithms::AntidoteSearchVariableCandidatesHeuristic>(),
// std::make_unique<algorithms::AntidoteSearchValueHeuristic>(),
// std::make_unique<algorithms::CulpritSearchErrorProjection>() );
_options );
}

is_optimization = units[0].data.is_optimization;
Expand Down
56 changes: 1 addition & 55 deletions src/algorithms/culprit_search_error_projection_heuristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@

#include "algorithms/culprit_search_error_projection_heuristic.hpp"

//#define TETEST

using ghost::algorithms::CulpritSearchErrorProjection;
using ghost::Variable;
using ghost::Constraint;
Expand All @@ -58,9 +56,6 @@ void CulpritSearchErrorProjection::compute_variable_errors_on_constraint( const

if( constraint->_current_error > 0 )
{
#if defined TETEST
std::cout << "\nconstraint->_current_error = " << constraint->_current_error;
#endif
int previous_value;
int next_value;

Expand All @@ -77,14 +72,7 @@ void CulpritSearchErrorProjection::compute_variable_errors_on_constraint( const
std::vector<int>{previous_value} )
+
constraint->simulate_delta( std::vector<int>{variable_id},
std::vector<int>{next_value} );

#if defined TETEST
std::cout << "\nvar[" << variable_id << "] = " << variables[ variable_id ].get_value()
<< "\nSim previous (" << previous_value << ") = " << constraint->simulate_delta( std::vector<int>{variable_id}, std::vector<int>{previous_value} )
<< "\nSim next (" << next_value << ") = " << constraint->simulate_delta( std::vector<int>{variable_id}, std::vector<int>{next_value} )
<< "\ncurrent_errors[ variable_id ] = " << current_errors[variable_id];
#endif
std::vector<int>{next_value} );
}
else
{
Expand All @@ -95,61 +83,29 @@ void CulpritSearchErrorProjection::compute_variable_errors_on_constraint( const
next_value = range[0];

current_errors[ variable_id ] = constraint->simulate_delta( std::vector<int>{variable_id}, std::vector<int>{next_value} );

#if defined TETEST
std::cout << "\nvar_id = " << variable_id
<< "\nSim next (" << next_value << ") = " << constraint->simulate_delta( std::vector<int>{variable_id}, std::vector<int>{next_value} )
<< "\ncurrent_errors[ variable_id ] = " << current_errors[variable_id];
#endif
}
else
{
current_errors[ variable_id ] = constraint->simulate_delta( std::vector<int>{variable_id}, std::vector<int>{variables[ variable_id ].get_value()} );

#if defined TETEST
std::cout << "\nvar_id = " << variable_id
<< "\ncurrent_errors[ variable_id ] = " << current_errors[variable_id];
#endif
}
}
}

double max = *std::max_element( current_errors.cbegin(), current_errors.cend() );
#if defined TETEST
std::cout << "\nMax = " << max << "\n";
#endif

// max becomes 0, the lowest delta becomes the highest one.
std::transform( current_errors.cbegin(),
current_errors.cend(),
current_errors.begin(),
[max](auto delta){ return -delta + max; } );
// std::transform( current_errors.cbegin(),
// current_errors.cend(),
// current_errors.begin(),
// [max](auto delta){ return delta == 0 ? 0 : -delta + max; } );

#if defined TETEST
std::cout << "New currents -delta + max\n";
std::copy( current_errors.begin(), current_errors.end(), std::ostream_iterator<double>(std::cout, " "));
#endif

double sum = std::accumulate( current_errors.cbegin(), current_errors.cend(), 0. );
#if defined TETEST
std::cout << "\nSum = " << sum << "\n";
#endif

// normalize deltas such that their sum equals to 1.
std::transform( current_errors.cbegin(),
current_errors.cend(),
current_errors.begin(),
[sum, &constraint](auto delta){ return delta == 0 ? 0 : ( delta / sum ) * constraint->_current_error; } );

#if defined TETEST
std::cout << "New currents ( delta / sum ) * constraint->_current_error\n";
std::copy( current_errors.begin(), current_errors.end(), std::ostream_iterator<double>(std::cout, " "));
std::cout << "\n\n";
#endif
}
}

Expand All @@ -163,10 +119,6 @@ void CulpritSearchErrorProjection::compute_variable_errors( std::vector<double>&
for( auto constraint : constraints )
{
compute_variable_errors_on_constraint( variables, matrix_var_ctr, constraint );

#if defined TETEST
std::copy( _error_variables_by_constraints[ constraint->_id ].begin(), _error_variables_by_constraints[ constraint->_id ].end(), std::ostream_iterator<double>(std::cout, " "));
#endif

// add normalize deltas of the current constraint to the error variables vector.
std::transform( _error_variables_by_constraints[ constraint->_id ].cbegin(),
Expand All @@ -175,12 +127,6 @@ void CulpritSearchErrorProjection::compute_variable_errors( std::vector<double>&
error_variables.begin(),
std::plus<>{} );
}

#if defined TETEST
std::cout << "\nCompute variable errors: ";
std::copy( error_variables.begin(), error_variables.end(), std::ostream_iterator<double>(std::cout, " "));
std::cout << "\n";
#endif
}

void CulpritSearchErrorProjection::update_variable_errors( std::vector<double>& error_variables,
Expand Down

0 comments on commit db91fa0

Please sign in to comment.