From d87b91c24d23b7ae8e78f8d127f5b9252c683843 Mon Sep 17 00:00:00 2001 From: Florian Richoux Date: Wed, 6 Mar 2024 09:56:30 +0900 Subject: [PATCH 01/11] Update copyright year --- .../algorithms/adaptive_search_error_projection_heuristic.hpp | 2 +- include/algorithms/adaptive_search_value_heuristic.hpp | 2 +- .../adaptive_search_variable_candidates_heuristic.hpp | 2 +- include/algorithms/adaptive_search_variable_heuristic.hpp | 2 +- include/algorithms/antidote_search_value_heuristic.hpp | 2 +- .../antidote_search_variable_candidates_heuristic.hpp | 2 +- include/algorithms/antidote_search_variable_heuristic.hpp | 2 +- .../algorithms/culprit_search_error_projection_heuristic.hpp | 2 +- include/algorithms/error_projection_heuristic.hpp | 2 +- include/algorithms/value_heuristic.hpp | 2 +- include/algorithms/variable_candidates_heuristic.hpp | 2 +- include/algorithms/variable_heuristic.hpp | 2 +- include/auxiliary_data.hpp | 2 +- include/constraint.hpp | 2 +- include/global_constraints/all_different.hpp | 2 +- include/global_constraints/all_equal.hpp | 2 +- include/global_constraints/fix_value.hpp | 2 +- include/global_constraints/linear_equation.hpp | 2 +- include/global_constraints/linear_equation_eq.hpp | 2 +- include/global_constraints/linear_equation_g.hpp | 2 +- include/global_constraints/linear_equation_geq.hpp | 2 +- include/global_constraints/linear_equation_l.hpp | 2 +- include/global_constraints/linear_equation_leq.hpp | 2 +- include/global_constraints/linear_equation_neq.hpp | 2 +- include/macros.hpp | 2 +- include/model.hpp | 2 +- include/model_builder.hpp | 2 +- include/objective.hpp | 2 +- include/options.hpp | 2 +- include/print.hpp | 2 +- include/search_unit.hpp | 2 +- include/search_unit_data.hpp | 2 +- include/solver.hpp | 2 +- include/variable.hpp | 2 +- src/algorithms/adaptive_search_error_projection_heuristic.cpp | 2 +- src/algorithms/adaptive_search_value_heuristic.cpp | 2 +- .../adaptive_search_variable_candidates_heuristic.cpp | 2 +- src/algorithms/adaptive_search_variable_heuristic.cpp | 2 +- src/algorithms/antidote_search_value_heuristic.cpp | 2 +- .../antidote_search_variable_candidates_heuristic.cpp | 2 +- src/algorithms/antidote_search_variable_heuristic.cpp | 2 +- src/algorithms/culprit_search_error_projection_heuristic.cpp | 2 +- src/auxiliary_data.cpp | 2 +- src/constraint.cpp | 2 +- src/global_constraints/all_different.cpp | 2 +- src/global_constraints/all_equal.cpp | 2 +- src/global_constraints/fix_value.cpp | 2 +- src/global_constraints/linear_equation.cpp | 2 +- src/global_constraints/linear_equation_eq.cpp | 2 +- src/global_constraints/linear_equation_g.cpp | 2 +- src/global_constraints/linear_equation_geq.cpp | 2 +- src/global_constraints/linear_equation_l.cpp | 2 +- src/global_constraints/linear_equation_leq.cpp | 2 +- src/global_constraints/linear_equation_neq.cpp | 2 +- src/model.cpp | 2 +- src/model_builder.cpp | 2 +- src/objective.cpp | 2 +- src/options.cpp | 2 +- src/print.cpp | 2 +- src/variable.cpp | 2 +- 60 files changed, 60 insertions(+), 60 deletions(-) diff --git a/include/algorithms/adaptive_search_error_projection_heuristic.hpp b/include/algorithms/adaptive_search_error_projection_heuristic.hpp index 910481c1..d1946b47 100644 --- a/include/algorithms/adaptive_search_error_projection_heuristic.hpp +++ b/include/algorithms/adaptive_search_error_projection_heuristic.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/algorithms/adaptive_search_value_heuristic.hpp b/include/algorithms/adaptive_search_value_heuristic.hpp index a7af83cf..db59891e 100644 --- a/include/algorithms/adaptive_search_value_heuristic.hpp +++ b/include/algorithms/adaptive_search_value_heuristic.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/algorithms/adaptive_search_variable_candidates_heuristic.hpp b/include/algorithms/adaptive_search_variable_candidates_heuristic.hpp index 74cfa462..c80020d1 100644 --- a/include/algorithms/adaptive_search_variable_candidates_heuristic.hpp +++ b/include/algorithms/adaptive_search_variable_candidates_heuristic.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/algorithms/adaptive_search_variable_heuristic.hpp b/include/algorithms/adaptive_search_variable_heuristic.hpp index 1c72b39c..64d8203c 100644 --- a/include/algorithms/adaptive_search_variable_heuristic.hpp +++ b/include/algorithms/adaptive_search_variable_heuristic.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/algorithms/antidote_search_value_heuristic.hpp b/include/algorithms/antidote_search_value_heuristic.hpp index b072986a..12259d4e 100644 --- a/include/algorithms/antidote_search_value_heuristic.hpp +++ b/include/algorithms/antidote_search_value_heuristic.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/algorithms/antidote_search_variable_candidates_heuristic.hpp b/include/algorithms/antidote_search_variable_candidates_heuristic.hpp index 602f5e98..1b29b7b9 100644 --- a/include/algorithms/antidote_search_variable_candidates_heuristic.hpp +++ b/include/algorithms/antidote_search_variable_candidates_heuristic.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/algorithms/antidote_search_variable_heuristic.hpp b/include/algorithms/antidote_search_variable_heuristic.hpp index e26c20e2..b0d64fcb 100644 --- a/include/algorithms/antidote_search_variable_heuristic.hpp +++ b/include/algorithms/antidote_search_variable_heuristic.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/algorithms/culprit_search_error_projection_heuristic.hpp b/include/algorithms/culprit_search_error_projection_heuristic.hpp index d56dad9a..17bcb6ab 100644 --- a/include/algorithms/culprit_search_error_projection_heuristic.hpp +++ b/include/algorithms/culprit_search_error_projection_heuristic.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/algorithms/error_projection_heuristic.hpp b/include/algorithms/error_projection_heuristic.hpp index 87a75c2f..c945193a 100644 --- a/include/algorithms/error_projection_heuristic.hpp +++ b/include/algorithms/error_projection_heuristic.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/algorithms/value_heuristic.hpp b/include/algorithms/value_heuristic.hpp index a9e64d91..9d0197f6 100644 --- a/include/algorithms/value_heuristic.hpp +++ b/include/algorithms/value_heuristic.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/algorithms/variable_candidates_heuristic.hpp b/include/algorithms/variable_candidates_heuristic.hpp index 4b3aca11..ed613a31 100644 --- a/include/algorithms/variable_candidates_heuristic.hpp +++ b/include/algorithms/variable_candidates_heuristic.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/algorithms/variable_heuristic.hpp b/include/algorithms/variable_heuristic.hpp index 6d72dedf..add87fa7 100644 --- a/include/algorithms/variable_heuristic.hpp +++ b/include/algorithms/variable_heuristic.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/auxiliary_data.hpp b/include/auxiliary_data.hpp index 13a49eaf..f52631e9 100644 --- a/include/auxiliary_data.hpp +++ b/include/auxiliary_data.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/constraint.hpp b/include/constraint.hpp index 5678beb4..0e42ada0 100644 --- a/include/constraint.hpp +++ b/include/constraint.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/global_constraints/all_different.hpp b/include/global_constraints/all_different.hpp index d990173b..93392ce6 100644 --- a/include/global_constraints/all_different.hpp +++ b/include/global_constraints/all_different.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/global_constraints/all_equal.hpp b/include/global_constraints/all_equal.hpp index 20664c46..f81f52ae 100644 --- a/include/global_constraints/all_equal.hpp +++ b/include/global_constraints/all_equal.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/global_constraints/fix_value.hpp b/include/global_constraints/fix_value.hpp index 0cb19589..ec4e0b8e 100644 --- a/include/global_constraints/fix_value.hpp +++ b/include/global_constraints/fix_value.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/global_constraints/linear_equation.hpp b/include/global_constraints/linear_equation.hpp index 878b784f..d5ae83a5 100644 --- a/include/global_constraints/linear_equation.hpp +++ b/include/global_constraints/linear_equation.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/global_constraints/linear_equation_eq.hpp b/include/global_constraints/linear_equation_eq.hpp index 74a0fc85..10b376c7 100644 --- a/include/global_constraints/linear_equation_eq.hpp +++ b/include/global_constraints/linear_equation_eq.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/global_constraints/linear_equation_g.hpp b/include/global_constraints/linear_equation_g.hpp index a7baa4e7..1ace0284 100644 --- a/include/global_constraints/linear_equation_g.hpp +++ b/include/global_constraints/linear_equation_g.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/global_constraints/linear_equation_geq.hpp b/include/global_constraints/linear_equation_geq.hpp index 4938d2c2..05222ad9 100644 --- a/include/global_constraints/linear_equation_geq.hpp +++ b/include/global_constraints/linear_equation_geq.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/global_constraints/linear_equation_l.hpp b/include/global_constraints/linear_equation_l.hpp index 7f43af19..3b12b5a3 100644 --- a/include/global_constraints/linear_equation_l.hpp +++ b/include/global_constraints/linear_equation_l.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/global_constraints/linear_equation_leq.hpp b/include/global_constraints/linear_equation_leq.hpp index d4cf4428..95c29965 100644 --- a/include/global_constraints/linear_equation_leq.hpp +++ b/include/global_constraints/linear_equation_leq.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/global_constraints/linear_equation_neq.hpp b/include/global_constraints/linear_equation_neq.hpp index d8d68f53..9ad33f99 100644 --- a/include/global_constraints/linear_equation_neq.hpp +++ b/include/global_constraints/linear_equation_neq.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/macros.hpp b/include/macros.hpp index dbdefea9..748e8c2d 100644 --- a/include/macros.hpp +++ b/include/macros.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/model.hpp b/include/model.hpp index 3c6182fa..379443f1 100644 --- a/include/model.hpp +++ b/include/model.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/model_builder.hpp b/include/model_builder.hpp index f39dad9a..ca630729 100644 --- a/include/model_builder.hpp +++ b/include/model_builder.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/objective.hpp b/include/objective.hpp index c686ac28..d4ff251e 100644 --- a/include/objective.hpp +++ b/include/objective.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/options.hpp b/include/options.hpp index c608d89f..ccc9f96c 100644 --- a/include/options.hpp +++ b/include/options.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/print.hpp b/include/print.hpp index 98b0fb6d..fe929a87 100644 --- a/include/print.hpp +++ b/include/print.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/search_unit.hpp b/include/search_unit.hpp index ed8bc45c..50c321df 100644 --- a/include/search_unit.hpp +++ b/include/search_unit.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/search_unit_data.hpp b/include/search_unit_data.hpp index dc5f13c2..359523c2 100644 --- a/include/search_unit_data.hpp +++ b/include/search_unit_data.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/solver.hpp b/include/solver.hpp index 56a3e4fd..0a35f27f 100644 --- a/include/solver.hpp +++ b/include/solver.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/include/variable.hpp b/include/variable.hpp index 1d4ef84a..cdcb27a8 100644 --- a/include/variable.hpp +++ b/include/variable.hpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/algorithms/adaptive_search_error_projection_heuristic.cpp b/src/algorithms/adaptive_search_error_projection_heuristic.cpp index ade52ddf..09d1e7d9 100644 --- a/src/algorithms/adaptive_search_error_projection_heuristic.cpp +++ b/src/algorithms/adaptive_search_error_projection_heuristic.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/algorithms/adaptive_search_value_heuristic.cpp b/src/algorithms/adaptive_search_value_heuristic.cpp index fa53387f..2b434e49 100644 --- a/src/algorithms/adaptive_search_value_heuristic.cpp +++ b/src/algorithms/adaptive_search_value_heuristic.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/algorithms/adaptive_search_variable_candidates_heuristic.cpp b/src/algorithms/adaptive_search_variable_candidates_heuristic.cpp index dc474cd5..d58829d8 100644 --- a/src/algorithms/adaptive_search_variable_candidates_heuristic.cpp +++ b/src/algorithms/adaptive_search_variable_candidates_heuristic.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/algorithms/adaptive_search_variable_heuristic.cpp b/src/algorithms/adaptive_search_variable_heuristic.cpp index 2b69ffee..10968886 100644 --- a/src/algorithms/adaptive_search_variable_heuristic.cpp +++ b/src/algorithms/adaptive_search_variable_heuristic.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/algorithms/antidote_search_value_heuristic.cpp b/src/algorithms/antidote_search_value_heuristic.cpp index 28cdf35a..12c51e61 100644 --- a/src/algorithms/antidote_search_value_heuristic.cpp +++ b/src/algorithms/antidote_search_value_heuristic.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/algorithms/antidote_search_variable_candidates_heuristic.cpp b/src/algorithms/antidote_search_variable_candidates_heuristic.cpp index c5d80fff..cea74585 100644 --- a/src/algorithms/antidote_search_variable_candidates_heuristic.cpp +++ b/src/algorithms/antidote_search_variable_candidates_heuristic.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/algorithms/antidote_search_variable_heuristic.cpp b/src/algorithms/antidote_search_variable_heuristic.cpp index 78f1b35b..b9706890 100644 --- a/src/algorithms/antidote_search_variable_heuristic.cpp +++ b/src/algorithms/antidote_search_variable_heuristic.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/algorithms/culprit_search_error_projection_heuristic.cpp b/src/algorithms/culprit_search_error_projection_heuristic.cpp index bed71c02..fe23346f 100644 --- a/src/algorithms/culprit_search_error_projection_heuristic.cpp +++ b/src/algorithms/culprit_search_error_projection_heuristic.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/auxiliary_data.cpp b/src/auxiliary_data.cpp index 9dd6bf0b..c4c27d0b 100644 --- a/src/auxiliary_data.cpp +++ b/src/auxiliary_data.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/constraint.cpp b/src/constraint.cpp index 266f7dfe..ff951533 100644 --- a/src/constraint.cpp +++ b/src/constraint.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/global_constraints/all_different.cpp b/src/global_constraints/all_different.cpp index 9188ea79..093eeadc 100644 --- a/src/global_constraints/all_different.cpp +++ b/src/global_constraints/all_different.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/global_constraints/all_equal.cpp b/src/global_constraints/all_equal.cpp index 67cab9c1..17d8a937 100644 --- a/src/global_constraints/all_equal.cpp +++ b/src/global_constraints/all_equal.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/global_constraints/fix_value.cpp b/src/global_constraints/fix_value.cpp index 02977ac0..15bcec9c 100644 --- a/src/global_constraints/fix_value.cpp +++ b/src/global_constraints/fix_value.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/global_constraints/linear_equation.cpp b/src/global_constraints/linear_equation.cpp index 1bac0689..33518ef9 100644 --- a/src/global_constraints/linear_equation.cpp +++ b/src/global_constraints/linear_equation.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/global_constraints/linear_equation_eq.cpp b/src/global_constraints/linear_equation_eq.cpp index c4b11a49..37d7cdf5 100644 --- a/src/global_constraints/linear_equation_eq.cpp +++ b/src/global_constraints/linear_equation_eq.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/global_constraints/linear_equation_g.cpp b/src/global_constraints/linear_equation_g.cpp index 74e3cf27..aa5dba91 100644 --- a/src/global_constraints/linear_equation_g.cpp +++ b/src/global_constraints/linear_equation_g.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/global_constraints/linear_equation_geq.cpp b/src/global_constraints/linear_equation_geq.cpp index 25292301..fc917dc3 100644 --- a/src/global_constraints/linear_equation_geq.cpp +++ b/src/global_constraints/linear_equation_geq.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/global_constraints/linear_equation_l.cpp b/src/global_constraints/linear_equation_l.cpp index f2be680e..246eb8a9 100644 --- a/src/global_constraints/linear_equation_l.cpp +++ b/src/global_constraints/linear_equation_l.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/global_constraints/linear_equation_leq.cpp b/src/global_constraints/linear_equation_leq.cpp index 1c7ddab5..89b0dc0a 100644 --- a/src/global_constraints/linear_equation_leq.cpp +++ b/src/global_constraints/linear_equation_leq.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/global_constraints/linear_equation_neq.cpp b/src/global_constraints/linear_equation_neq.cpp index cbfa83b9..a50e13ea 100644 --- a/src/global_constraints/linear_equation_neq.cpp +++ b/src/global_constraints/linear_equation_neq.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/model.cpp b/src/model.cpp index 4012aa72..b2d85f08 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/model_builder.cpp b/src/model_builder.cpp index 452e4570..4ec1ec2a 100644 --- a/src/model_builder.cpp +++ b/src/model_builder.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/objective.cpp b/src/objective.cpp index de85df22..b55fde42 100644 --- a/src/objective.cpp +++ b/src/objective.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/options.cpp b/src/options.cpp index 338a31b9..cc638e34 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/print.cpp b/src/print.cpp index 3fb3a98f..1741f290 100644 --- a/src/print.cpp +++ b/src/print.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or diff --git a/src/variable.cpp b/src/variable.cpp index 200765b8..8f571e1d 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -10,7 +10,7 @@ * within some milliseconds, making it very suitable for highly reactive or embedded systems. * Please visit https://github.com/richoux/GHOST for further information. * - * Copyright (C) 2014-2023 Florian Richoux + * Copyright (C) 2014-2024 Florian Richoux * * This file is part of GHOST. * GHOST is free software: you can redistribute it and/or From a48ff542ded37bcf56a4829f9a26244e1b134a6c Mon Sep 17 00:00:00 2001 From: Florian Richoux Date: Wed, 6 Mar 2024 12:09:09 +0900 Subject: [PATCH 02/11] Improve traces --- include/search_unit.hpp | 39 +++++++++++++++++++++++++++++++-------- include/solver.hpp | 8 +++++--- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/include/search_unit.hpp b/include/search_unit.hpp index 50c321df..78bbc2fe 100644 --- a/include/search_unit.hpp +++ b/include/search_unit.hpp @@ -87,6 +87,12 @@ namespace ghost #endif #if defined GHOST_TRACE + void print_current_candidate() + { + for( int variable_id = 0 ; variable_id < data.number_variables ; ++variable_id ) + COUT << model.variables[variable_id].get_value() << " "; + } + void print_errors() { COUT << "Constraint errors:\n"; @@ -165,7 +171,9 @@ namespace ghost if( data.best_sat_error > best_sat_error_so_far ) { #if defined GHOST_TRACE - COUT << "Better starting configuration found. Previous error: " << data.best_sat_error << ", now: " << best_sat_error_so_far << "\n"; + COUT << "Better starting configuration found: "; + print_current_candidate(); + COUT << "\nPrevious error: " << data.best_sat_error << ", now: " << best_sat_error_so_far << "\n\n"; #endif data.best_sat_error = best_sat_error_so_far; } @@ -721,12 +729,15 @@ namespace ghost #if defined GHOST_TRACE COUT << options.print->print_candidate( model.variables ).str(); - COUT << "\n\nNumber of loop iteration: " << data.search_iterations << "\n"; + COUT << "\n********\nNumber of loop iteration: " << data.search_iterations << "\n"; COUT << "Number of local moves performed: " << data.local_moves << "\n"; COUT << "Tabu list :"; for( int i = 0 ; i < data.number_variables ; ++i ) if( data.tabu_list[i] > data.local_moves ) COUT << " v[" << i << "]:<" << data.tabu_list[i] << ">"; + COUT << "\n\nCurrent candidate: "; + print_current_candidate(); + COUT << "\nCurrent error: " << data.current_sat_error; COUT << "\nPicked worst variable: v[" << variable_to_change << "]=" << model.variables[ variable_to_change ].get_value() << "\n\n"; #endif // end GHOST_TRACE @@ -888,12 +899,10 @@ namespace ghost if( model.permutation_problem ) COUT << "\nPicked variable index for min conflict: " << new_value << "\n" - << "Current error: " << data.current_sat_error << "\n" << "Delta: " << min_conflict << "\n\n"; else COUT << "\nPicked value for min conflict: " << new_value << "\n" - << "Current error: " << data.current_sat_error << "\n" << "Delta: " << min_conflict << "\n\n"; #endif // GHOST_TRACE @@ -961,7 +970,7 @@ namespace ghost if( data.current_opt_cost > candidate_opt_cost ) { #if defined GHOST_TRACE - COUT << "optimization cost improved (" << data.current_opt_cost << " -> " << candidate_opt_cost << "): make local move.\n"; + COUT << "Optimization cost improved (" << data.current_opt_cost << " -> " << candidate_opt_cost << "): make local move.\n"; #endif local_move( variable_to_change, new_value, min_conflict, delta_errors ); data.current_opt_cost = candidate_opt_cost; @@ -973,7 +982,7 @@ namespace ghost if( data.current_opt_cost == candidate_opt_cost ) { #if defined GHOST_TRACE - COUT << "optimization cost stable (" << data.current_opt_cost << "): plateau.\n"; + COUT << "Optimization cost stable (" << data.current_opt_cost << "): plateau.\n"; #endif plateau_management( variable_to_change, new_value, delta_errors ); } @@ -983,7 +992,14 @@ namespace ghost * 4.c. Worst optimization cost => local minimum * *************************************************/ #if defined GHOST_TRACE - COUT << "optimization cost increase (" << data.current_opt_cost << " -> " << candidate_opt_cost << "): local minimum.\n"; + COUT << "Optimization cost increase (" << data.current_opt_cost << " -> " << candidate_opt_cost << "): local minimum.\n"; + // Real local minimum in the following case + if( variable_candidates.empty() ) + { + COUT << "Local minimum candidate: "; + print_current_candidate(); + COUT << "\nLocal minimum cost: " << data.current_opt_cost << "\n"; + } #endif local_minimum_management( variable_to_change, new_value, variable_candidates.empty() ); } @@ -994,7 +1010,7 @@ namespace ghost * 4.d. Not an optimization problem => plateau * ***********************************************/ #if defined GHOST_TRACE - COUT << "no optimization: plateau.\n"; + COUT << "No optimization: plateau.\n"; #endif plateau_management( variable_to_change, new_value, delta_errors ); } @@ -1006,6 +1022,13 @@ namespace ghost ***********************************/ #if defined GHOST_TRACE COUT << "Global error increase: local minimum.\n"; + // Real local minimum in the following case + if( variable_candidates.empty() ) + { + COUT << "Local minimum candidate: "; + print_current_candidate(); + COUT << "\nLocal minimum error: " << data.current_sat_error << "\n"; + } #endif local_minimum_management( variable_to_change, new_value, variable_candidates.empty() ); } diff --git a/include/solver.hpp b/include/solver.hpp index 0a35f27f..2fd45a31 100644 --- a/include/solver.hpp +++ b/include/solver.hpp @@ -736,9 +736,11 @@ namespace ghost std::cout << "############" << "\n"; // Print solution - std::cout << _options.print->print_candidate( _model.variables ).str(); - - std::cout << "\n"; + std::cout << "Solution: "; + for (const auto& v: _model.variables) + std::cout << v.get_value() << " "; + + std::cout << "\n" << _options.print->print_candidate( _model.variables ).str() << "\n"; if( !is_optimization ) std::cout << "SATISFACTION run" << "\n"; From be02122ac75ade67afab73c4e673084269e08600 Mon Sep 17 00:00:00 2001 From: Florian Richoux Date: Wed, 6 Mar 2024 18:06:19 +0900 Subject: [PATCH 03/11] Comment strategy classes --- .../adaptive_search_variable_heuristic.hpp | 2 +- .../antidote_search_variable_heuristic.hpp | 2 +- .../algorithms/error_projection_heuristic.hpp | 8 +++++- include/algorithms/value_heuristic.hpp | 28 +++++++++++++------ .../variable_candidates_heuristic.hpp | 13 ++++++--- include/algorithms/variable_heuristic.hpp | 17 +++++++---- include/search_unit.hpp | 7 +++-- .../adaptive_search_value_heuristic.cpp | 12 ++++---- .../adaptive_search_variable_heuristic.cpp | 2 +- .../antidote_search_value_heuristic.cpp | 12 ++++---- .../antidote_search_variable_heuristic.cpp | 2 +- 11 files changed, 68 insertions(+), 37 deletions(-) diff --git a/include/algorithms/adaptive_search_variable_heuristic.hpp b/include/algorithms/adaptive_search_variable_heuristic.hpp index 64d8203c..85a323a4 100644 --- a/include/algorithms/adaptive_search_variable_heuristic.hpp +++ b/include/algorithms/adaptive_search_variable_heuristic.hpp @@ -42,7 +42,7 @@ namespace ghost public: AdaptiveSearchVariableHeuristic(); - int select_variable_candidate( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const override; + int select_variable( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const override; }; } } diff --git a/include/algorithms/antidote_search_variable_heuristic.hpp b/include/algorithms/antidote_search_variable_heuristic.hpp index b0d64fcb..b70224d2 100644 --- a/include/algorithms/antidote_search_variable_heuristic.hpp +++ b/include/algorithms/antidote_search_variable_heuristic.hpp @@ -42,7 +42,7 @@ namespace ghost public: AntidoteSearchVariableHeuristic(); - int select_variable_candidate( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const override; + int select_variable( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const override; }; } } diff --git a/include/algorithms/error_projection_heuristic.hpp b/include/algorithms/error_projection_heuristic.hpp index c945193a..1b5388f6 100644 --- a/include/algorithms/error_projection_heuristic.hpp +++ b/include/algorithms/error_projection_heuristic.hpp @@ -39,9 +39,13 @@ namespace ghost { namespace algorithms { + /* + * Strategy design pattern to implement error projection heuristics. + */ class ErrorProjection { protected: + // Protected string variable for the heuristic name. Used for debug/trace purposes. std::string name; int number_variables; int number_constraints; @@ -51,13 +55,15 @@ namespace ghost : name( std::move( name ) ) { } - //! Default virtual destructor. + // Default virtual destructor. virtual ~ErrorProjection() = default; + // Inline function returning the heuristic name. inline std::string get_name() const { return name; } inline void set_number_variables( int num ) { number_variables = num ; } inline void set_number_constraints( int num ) { number_constraints = num ; } + // This function can be useful to initialize some data structures before computing error projections. virtual void initialize_data_structures() {}; virtual void compute_variable_errors( std::vector& error_variables, diff --git a/include/algorithms/value_heuristic.hpp b/include/algorithms/value_heuristic.hpp index 9d0197f6..f0c5473d 100644 --- a/include/algorithms/value_heuristic.hpp +++ b/include/algorithms/value_heuristic.hpp @@ -41,11 +41,12 @@ namespace ghost namespace algorithms { /* - * ValueHeuristic follows the Strategy design pattern to implement variable selection heuristics. + * Strategy design pattern to implement variable selection heuristics. */ class ValueHeuristic { protected: + // Protected string variable for the heuristic name. Used for debug/trace purposes. std::string name; public: @@ -53,17 +54,28 @@ namespace ghost : name( std::move( name ) ) { } - //! Default virtual destructor. + // Default virtual destructor. virtual ~ValueHeuristic() = default; + // Inline function returning the heuristic name. inline std::string get_name() const { return name; } - virtual int select_value_candidates( int variable_to_change, - const SearchUnitData& data, - const Model& model, - const std::map>& delta_errors, - double& min_conflict, - randutils::mt19937_rng& rng ) const = 0; + /* + * Function to select a value to assign to the variable currently selected by the search algorithm to make a local move. + * \param variable_to_change The index of the variable currently selected by the search algorithm. + * \param data A reference to the SearchUnitData object containing data about the problem instance and the search state, such as the number of variables and constraints, the current projected error on each variable, etc. + * \param model A reference to the problem model, to get access to the objective function for instance. + * \param delta_errors A reference to a map to have the list of delta errors on each variable. + * \param min_conflict A non-constant reference to get the minimal conflict value after calling this function. + * \param rng A reference to the pseudo-random generator, to avoid recreating such object. + * \return The selected value to be assigned to variable_to_change (or the index of a variable in case of permutation moves). + */ + virtual int select_value( int variable_to_change, + const SearchUnitData& data, + const Model& model, + const std::map>& delta_errors, + double& min_conflict, + randutils::mt19937_rng& rng ) const = 0; }; } } diff --git a/include/algorithms/variable_candidates_heuristic.hpp b/include/algorithms/variable_candidates_heuristic.hpp index ed613a31..6ef526b4 100644 --- a/include/algorithms/variable_candidates_heuristic.hpp +++ b/include/algorithms/variable_candidates_heuristic.hpp @@ -39,11 +39,12 @@ namespace ghost namespace algorithms { /* - * VariableCandidatesHeuristic follows the Strategy design pattern to implement variable candidates selection heuristics. + * Strategy design pattern to implement variable candidates selection heuristics. */ class VariableCandidatesHeuristic { protected: + // Protected string variable for the heuristic name. Used for debug/trace purposes. std::string name; public: @@ -51,13 +52,17 @@ namespace ghost : name( std::move( name ) ) { } - //! Default virtual destructor. + // Default virtual destructor. virtual ~VariableCandidatesHeuristic() = default; + // Inline function returning the heuristic name. inline std::string get_name() const { return name; } - // returns a vector of double to be more generic, allowing for instance a vector of errors - // rather than a vector of ID, like it would certainly be often the case in practice. + /* + * Function to compute variable candidates, for instance regarding their projected error. + * \param data A reference to the SearchUnitData object containing data about the problem instance and the search state, such as the number of variables and constraints, the current projected error on each variable, etc. + * \return A vector of double to be more generic, allowing for instance a vector of errors rather than a vector of ID. + */ virtual std::vector compute_variable_candidates( const SearchUnitData& data ) const = 0; }; } diff --git a/include/algorithms/variable_heuristic.hpp b/include/algorithms/variable_heuristic.hpp index add87fa7..e594efe5 100644 --- a/include/algorithms/variable_heuristic.hpp +++ b/include/algorithms/variable_heuristic.hpp @@ -40,11 +40,12 @@ namespace ghost namespace algorithms { /* - * VariableHeuristic follows the Strategy design pattern to implement variable selection heuristics. + * Strategy design pattern to implement variable selection heuristics. */ class VariableHeuristic { protected: + // Protected string variable for the heuristic name. Used for debug/trace purposes. std::string name; public: @@ -52,14 +53,20 @@ namespace ghost : name( std::move( name ) ) { } - //! Default virtual destructor. + // Default virtual destructor. virtual ~VariableHeuristic() = default; + // Inline function returning the heuristic name. inline std::string get_name() const { return name; } - // candidates is a vector of double to be more generic, allowing for instance a vector of errors - // rather than a vector of ID, like it would certainly be often the case in practice. - virtual int select_variable_candidate( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const = 0; + /* + * Function to select, among a vector of candidates, a variable from which the search algorithm will make a local move. + * \param candidates A const reference to a double vector to be more generic, allowing for instance a vector of errors, rather than a vector of ID, although it would certainly be often the case in practice. + * \param data A reference to the SearchUnitData object containing data about the problem instance and the search state, such as the number of variables and constraints, the current projected error on each variable, etc. + * \param rng A reference to the pseudo-random generator, to avoid recreating such object. + * \return The index of the selected variable in the candidates vector. + */ + virtual int select_variable( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const = 0; }; } } diff --git a/include/search_unit.hpp b/include/search_unit.hpp index 78bbc2fe..49c2f6ca 100644 --- a/include/search_unit.hpp +++ b/include/search_unit.hpp @@ -674,7 +674,8 @@ namespace ghost COUT << "Projected error of var[" << i << "]: " << data.error_variables[i] << "\n"; #endif - + + // TODO: to replace after a potential reset() call (l700), to save some computations? // Estimate which variables need to be changed if( must_compute_variable_candidates ) variable_candidates = variable_candidates_heuristic->compute_variable_candidates( data ); @@ -725,7 +726,7 @@ namespace ghost } #endif - variable_to_change = variable_heuristic->select_variable_candidate( variable_candidates, data, rng ); + variable_to_change = variable_heuristic->select_variable( variable_candidates, data, rng ); #if defined GHOST_TRACE COUT << options.print->print_candidate( model.variables ).str(); @@ -810,7 +811,7 @@ namespace ghost // Select the next current configuration (local move) double min_conflict = std::numeric_limits::max(); - int new_value = value_heuristic->select_value_candidates( variable_to_change, data, model, delta_errors, min_conflict, rng ); + int new_value = value_heuristic->select_value( variable_to_change, data, model, delta_errors, min_conflict, rng ); #if defined GHOST_TRACE diff --git a/src/algorithms/adaptive_search_value_heuristic.cpp b/src/algorithms/adaptive_search_value_heuristic.cpp index 2b434e49..7b56b905 100644 --- a/src/algorithms/adaptive_search_value_heuristic.cpp +++ b/src/algorithms/adaptive_search_value_heuristic.cpp @@ -40,12 +40,12 @@ AdaptiveSearchValueHeuristic::AdaptiveSearchValueHeuristic() : ValueHeuristic( "Adaptive Search" ) { } -int AdaptiveSearchValueHeuristic::select_value_candidates( int variable_to_change, - const SearchUnitData& data, - const Model& model, - const std::map>& delta_errors, - double& min_conflict, - randutils::mt19937_rng& rng ) const +int AdaptiveSearchValueHeuristic::select_value( int variable_to_change, + const SearchUnitData& data, + const Model& model, + const std::map>& delta_errors, + double& min_conflict, + randutils::mt19937_rng& rng ) const { std::vector candidate_values; std::map cumulated_delta_errors; diff --git a/src/algorithms/adaptive_search_variable_heuristic.cpp b/src/algorithms/adaptive_search_variable_heuristic.cpp index 10968886..54eb8a88 100644 --- a/src/algorithms/adaptive_search_variable_heuristic.cpp +++ b/src/algorithms/adaptive_search_variable_heuristic.cpp @@ -35,7 +35,7 @@ AdaptiveSearchVariableHeuristic::AdaptiveSearchVariableHeuristic() : VariableHeuristic( "Adaptive Search" ) { } -int AdaptiveSearchVariableHeuristic::select_variable_candidate( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const +int AdaptiveSearchVariableHeuristic::select_variable( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const { return static_cast( rng.pick( candidates ) ); } diff --git a/src/algorithms/antidote_search_value_heuristic.cpp b/src/algorithms/antidote_search_value_heuristic.cpp index 12c51e61..d58c3362 100644 --- a/src/algorithms/antidote_search_value_heuristic.cpp +++ b/src/algorithms/antidote_search_value_heuristic.cpp @@ -39,12 +39,12 @@ AntidoteSearchValueHeuristic::AntidoteSearchValueHeuristic() : ValueHeuristic( "Antidote Search" ) { } -int AntidoteSearchValueHeuristic::select_value_candidates( int variable_to_change, - const SearchUnitData& data, - const Model& model, - const std::map>& delta_errors, - double& min_conflict, - randutils::mt19937_rng& rng ) const +int AntidoteSearchValueHeuristic::select_value( int variable_to_change, + const SearchUnitData& data, + const Model& model, + const std::map>& delta_errors, + double& min_conflict, + randutils::mt19937_rng& rng ) const { std::vector cumulated_delta_errors( delta_errors.size() ); std::vector cumulated_delta_errors_for_distribution( delta_errors.size() ); diff --git a/src/algorithms/antidote_search_variable_heuristic.cpp b/src/algorithms/antidote_search_variable_heuristic.cpp index b9706890..5078a130 100644 --- a/src/algorithms/antidote_search_variable_heuristic.cpp +++ b/src/algorithms/antidote_search_variable_heuristic.cpp @@ -36,7 +36,7 @@ AntidoteSearchVariableHeuristic::AntidoteSearchVariableHeuristic() : VariableHeuristic( "Antidote Search" ) { } -int AntidoteSearchVariableHeuristic::select_variable_candidate( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const +int AntidoteSearchVariableHeuristic::select_variable( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const { // WARNING: must remove variables which are in any constraints return rng.variate( candidates.begin(), candidates.end() ); From 01f69b0c8763ae2b4550ed260a723fc218c6ae3d Mon Sep 17 00:00:00 2001 From: Florian Richoux Date: Thu, 7 Mar 2024 08:43:46 +0900 Subject: [PATCH 04/11] Change 'select_value' function name --- .../algorithms/adaptive_search_value_heuristic.hpp | 12 ++++++------ .../algorithms/antidote_search_value_heuristic.hpp | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/algorithms/adaptive_search_value_heuristic.hpp b/include/algorithms/adaptive_search_value_heuristic.hpp index db59891e..ff17afd4 100644 --- a/include/algorithms/adaptive_search_value_heuristic.hpp +++ b/include/algorithms/adaptive_search_value_heuristic.hpp @@ -42,12 +42,12 @@ namespace ghost public: AdaptiveSearchValueHeuristic(); - int select_value_candidates( int variable_to_change, - const SearchUnitData& data, - const Model& model, - const std::map>& delta_errors, - double& min_conflict, - randutils::mt19937_rng& rng ) const override; + int select_value( int variable_to_change, + const SearchUnitData& data, + const Model& model, + const std::map>& delta_errors, + double& min_conflict, + randutils::mt19937_rng& rng ) const override; }; } } diff --git a/include/algorithms/antidote_search_value_heuristic.hpp b/include/algorithms/antidote_search_value_heuristic.hpp index 12259d4e..4f044d9f 100644 --- a/include/algorithms/antidote_search_value_heuristic.hpp +++ b/include/algorithms/antidote_search_value_heuristic.hpp @@ -42,12 +42,12 @@ namespace ghost public: AntidoteSearchValueHeuristic(); - int select_value_candidates( int variable_to_change, - const SearchUnitData& data, - const Model& model, - const std::map>& delta_errors, - double& min_conflict, - randutils::mt19937_rng& rng ) const override; + int select_value( int variable_to_change, + const SearchUnitData& data, + const Model& model, + const std::map>& delta_errors, + double& min_conflict, + randutils::mt19937_rng& rng ) const override; }; } } From 0e1bb7d1c42171162434f81e0ee8d9ee075e0483 Mon Sep 17 00:00:00 2001 From: Florian Richoux Date: Thu, 7 Mar 2024 11:59:55 +0900 Subject: [PATCH 05/11] Rename error projection files and make it more uniform with other classes in ghost::algorithms --- CMakeLists.txt | 10 ++--- ...ive_search_error_projection_algorithm.hpp} | 14 +++---- ...rit_search_error_projection_algorithm.hpp} | 16 ++++---- ...tic.hpp => error_projection_algorithm.hpp} | 27 ++++++------- include/search_unit.hpp | 39 ++++++++----------- include/search_unit_data.hpp | 1 + include/solver.hpp | 16 ++++---- ...ive_search_error_projection_algorithm.cpp} | 24 ++++++------ ...rit_search_error_projection_algorithm.cpp} | 36 ++++++++--------- 9 files changed, 83 insertions(+), 100 deletions(-) rename include/algorithms/{adaptive_search_error_projection_heuristic.hpp => adaptive_search_error_projection_algorithm.hpp} (78%) rename include/algorithms/{culprit_search_error_projection_heuristic.hpp => culprit_search_error_projection_algorithm.hpp} (79%) rename include/algorithms/{error_projection_heuristic.hpp => error_projection_algorithm.hpp} (69%) rename src/algorithms/{adaptive_search_error_projection_heuristic.cpp => adaptive_search_error_projection_algorithm.cpp} (68%) rename src/algorithms/{culprit_search_error_projection_heuristic.cpp => culprit_search_error_projection_algorithm.cpp} (80%) diff --git a/CMakeLists.txt b/CMakeLists.txt index db0d2678..ee28e2a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,15 +101,15 @@ set(libHeadersAlgorithmsList "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/variable_heuristic.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/variable_candidates_heuristic.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/value_heuristic.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/error_projection_heuristic.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/error_projection_algorithm.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/adaptive_search_variable_heuristic.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/adaptive_search_variable_candidates_heuristic.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/adaptive_search_value_heuristic.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/adaptive_search_error_projection_heuristic.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/adaptive_search_error_projection_algorithm.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/antidote_search_variable_heuristic.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/antidote_search_variable_candidates_heuristic.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/antidote_search_value_heuristic.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/culprit_search_error_projection_heuristic.hpp") + "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/culprit_search_error_projection_algorithm.hpp") set(libHeadersGlobalConstraintsList "${CMAKE_CURRENT_SOURCE_DIR}/include/global_constraints/all_different.hpp" @@ -141,11 +141,11 @@ set(toAddInLibs src/algorithms/adaptive_search_variable_heuristic.cpp src/algorithms/adaptive_search_variable_candidates_heuristic.cpp src/algorithms/adaptive_search_value_heuristic.cpp - src/algorithms/adaptive_search_error_projection_heuristic.cpp + src/algorithms/adaptive_search_error_projection_algorithm.cpp src/algorithms/antidote_search_variable_heuristic.cpp src/algorithms/antidote_search_variable_candidates_heuristic.cpp src/algorithms/antidote_search_value_heuristic.cpp - src/algorithms/culprit_search_error_projection_heuristic.cpp + src/algorithms/culprit_search_error_projection_algorithm.cpp src/global_constraints/all_different.cpp src/global_constraints/all_equal.cpp src/global_constraints/fix_value.cpp diff --git a/include/algorithms/adaptive_search_error_projection_heuristic.hpp b/include/algorithms/adaptive_search_error_projection_algorithm.hpp similarity index 78% rename from include/algorithms/adaptive_search_error_projection_heuristic.hpp rename to include/algorithms/adaptive_search_error_projection_algorithm.hpp index d1946b47..4006265c 100644 --- a/include/algorithms/adaptive_search_error_projection_heuristic.hpp +++ b/include/algorithms/adaptive_search_error_projection_algorithm.hpp @@ -29,7 +29,7 @@ #pragma once -#include "error_projection_heuristic.hpp" +#include "error_projection_algorithm.hpp" namespace ghost { @@ -40,15 +40,13 @@ namespace ghost public: AdaptiveSearchErrorProjection(); - void compute_variable_errors( std::vector& error_variables, - const std::vector& variables, - const std::vector>& matrix_var_ctr, - const std::vector>& constraints ) override; + void compute_variable_errors( const std::vector& variables, + const std::vector>& constraints, + SearchUnitData& data ) override; - void update_variable_errors( std::vector& error_variables, - const std::vector& variables, - const std::vector>& matrix_var_ctr, + void update_variable_errors( const std::vector& variables, std::shared_ptr constraint, + SearchUnitData& data, double delta ) override; }; } diff --git a/include/algorithms/culprit_search_error_projection_heuristic.hpp b/include/algorithms/culprit_search_error_projection_algorithm.hpp similarity index 79% rename from include/algorithms/culprit_search_error_projection_heuristic.hpp rename to include/algorithms/culprit_search_error_projection_algorithm.hpp index 17bcb6ab..677e1496 100644 --- a/include/algorithms/culprit_search_error_projection_heuristic.hpp +++ b/include/algorithms/culprit_search_error_projection_algorithm.hpp @@ -29,7 +29,7 @@ #pragma once -#include "error_projection_heuristic.hpp" +#include "error_projection_algorithm.hpp" namespace ghost { @@ -46,17 +46,15 @@ namespace ghost public: CulpritSearchErrorProjection(); - void initialize_data_structures() override; + void initialize_data_structures( const SearchUnitData& data ) override; - void compute_variable_errors( std::vector& error_variables, - const std::vector& variables, - const std::vector>& matrix_var_ctr, - const std::vector>& constraints ) override; + void compute_variable_errors( const std::vector& variables, + const std::vector>& constraints, + SearchUnitData& data ) override; - void update_variable_errors( std::vector& error_variables, - const std::vector& variables, - const std::vector>& matrix_var_ctr, + void update_variable_errors( const std::vector& variables, std::shared_ptr constraint, + SearchUnitData& data, double delta ) override; }; } diff --git a/include/algorithms/error_projection_heuristic.hpp b/include/algorithms/error_projection_algorithm.hpp similarity index 69% rename from include/algorithms/error_projection_heuristic.hpp rename to include/algorithms/error_projection_algorithm.hpp index 1b5388f6..28c21850 100644 --- a/include/algorithms/error_projection_heuristic.hpp +++ b/include/algorithms/error_projection_algorithm.hpp @@ -32,6 +32,7 @@ #include #include +#include "../search_unit_data.hpp" #include "../constraint.hpp" #include "../variable.hpp" @@ -40,15 +41,13 @@ namespace ghost namespace algorithms { /* - * Strategy design pattern to implement error projection heuristics. + * Strategy design pattern to implement error projection algorithm. */ class ErrorProjection { protected: // Protected string variable for the heuristic name. Used for debug/trace purposes. std::string name; - int number_variables; - int number_constraints; public: ErrorProjection( std::string&& name ) @@ -58,23 +57,21 @@ namespace ghost // Default virtual destructor. virtual ~ErrorProjection() = default; - // Inline function returning the heuristic name. + // Inline function returning the algorithm name. inline std::string get_name() const { return name; } - inline void set_number_variables( int num ) { number_variables = num ; } - inline void set_number_constraints( int num ) { number_constraints = num ; } - // This function can be useful to initialize some data structures before computing error projections. - virtual void initialize_data_structures() {}; + // Can be useful to initialize some data structures before computing error projections. + virtual void initialize_data_structures( const SearchUnitData& data ) {}; - virtual void compute_variable_errors( std::vector& error_variables, - const std::vector& variables, - const std::vector>& matrix_var_ctr, - const std::vector>& constraints ) = 0; + // Will reset data.error_variables and set the element of this vector to their projected cost + virtual void compute_variable_errors( const std::vector& variables, + const std::vector>& constraints, + SearchUnitData& data ) = 0; - virtual void update_variable_errors( std::vector& error_variables, - const std::vector& variables, - const std::vector>& matrix_var_ctr, + // Incremental update of data.error_variables + virtual void update_variable_errors( const std::vector& variables, std::shared_ptr constraint, + SearchUnitData& data, double delta ) = 0; }; } diff --git a/include/search_unit.hpp b/include/search_unit.hpp index 49c2f6ca..6821d28c 100644 --- a/include/search_unit.hpp +++ b/include/search_unit.hpp @@ -54,18 +54,18 @@ #include "algorithms/variable_heuristic.hpp" #include "algorithms/variable_candidates_heuristic.hpp" #include "algorithms/value_heuristic.hpp" -#include "algorithms/error_projection_heuristic.hpp" +#include "algorithms/error_projection_algorithm.hpp" #include "algorithms/adaptive_search_variable_heuristic.hpp" #include "algorithms/adaptive_search_variable_candidates_heuristic.hpp" #include "algorithms/adaptive_search_value_heuristic.hpp" -#include "algorithms/adaptive_search_error_projection_heuristic.hpp" +#include "algorithms/adaptive_search_error_projection_algorithm.hpp" #include "algorithms/antidote_search_variable_heuristic.hpp" #include "algorithms/antidote_search_variable_candidates_heuristic.hpp" #include "algorithms/antidote_search_value_heuristic.hpp" -#include "algorithms/culprit_search_error_projection_heuristic.hpp" +#include "algorithms/culprit_search_error_projection_algorithm.hpp" #include "macros.hpp" @@ -302,10 +302,9 @@ namespace ghost } // Reset variable costs and recompute them - error_projection_heuristic->compute_variable_errors( data.error_variables, - model.variables, - data.matrix_var_ctr, - model.constraints ); + error_projection_algorithm->compute_variable_errors( model.variables, + model.constraints, + data ); } void initialize_data_structures( Model& model ) @@ -384,10 +383,9 @@ namespace ghost auto delta = delta_errors.at( new_value )[ delta_index++ ]; model.constraints[ constraint_id ]->_current_error += delta; - error_projection_heuristic->update_variable_errors( data.error_variables, - model.variables, - data.matrix_var_ctr, + error_projection_algorithm->update_variable_errors( model.variables, model.constraints[ constraint_id ], + data, delta ); model.constraints[ constraint_id ]->update( variable_to_change, new_value ); @@ -408,10 +406,9 @@ namespace ghost auto delta = delta_errors.at( new_value )[ delta_index++ ]; model.constraints[ constraint_id ]->_current_error += delta; - error_projection_heuristic->update_variable_errors( data.error_variables, - model.variables, - data.matrix_var_ctr, + error_projection_algorithm->update_variable_errors( model.variables, model.constraints[ constraint_id ], + data, delta ); model.constraints[ constraint_id ]->update( variable_to_change, next_value ); @@ -426,10 +423,9 @@ namespace ghost auto delta = delta_errors.at( new_value )[ delta_index++ ]; model.constraints[ constraint_id ]->_current_error += delta; - error_projection_heuristic->update_variable_errors( data.error_variables, - model.variables, - data.matrix_var_ctr, + error_projection_algorithm->update_variable_errors( model.variables, model.constraints[ constraint_id ], + data, delta ); model.constraints[ constraint_id ]->update( new_value, current_value ); @@ -521,7 +517,7 @@ namespace ghost std::unique_ptr variable_heuristic; std::unique_ptr variable_candidates_heuristic; std::unique_ptr value_heuristic; - std::unique_ptr error_projection_heuristic; + std::unique_ptr error_projection_algorithm; std::vector final_solution; @@ -537,14 +533,14 @@ namespace ghost std::unique_ptr variable_heuristic, std::unique_ptr variable_candidates_heuristic, std::unique_ptr value_heuristic, - std::unique_ptr error_projection_heuristic ) + std::unique_ptr error_projection_algorithm ) : _stop_search_check( _stop_search_signal.get_future() ), model( std::move( moved_model ) ), data( model ), variable_heuristic( std::move( variable_heuristic ) ), variable_candidates_heuristic( std::move( variable_candidates_heuristic ) ), value_heuristic( std::move( value_heuristic ) ), - error_projection_heuristic( std::move( error_projection_heuristic ) ), + error_projection_algorithm( std::move( error_projection_algorithm ) ), final_solution( std::vector( data.number_variables, 0 ) ), variable_candidates(), must_compute_variable_candidates ( true ), @@ -557,10 +553,7 @@ namespace ghost initialize_data_structures( model ); data.initialize_matrix( model ); - - this->error_projection_heuristic->set_number_variables( data.number_variables ); - this->error_projection_heuristic->set_number_constraints( data.number_constraints ); - this->error_projection_heuristic->initialize_data_structures(); + this->error_projection_algorithm->initialize_data_structures( data ); #if defined GHOST_TRACE COUT << "Creating a Solver object\n\n" diff --git a/include/search_unit_data.hpp b/include/search_unit_data.hpp index 359523c2..91c9b2b6 100644 --- a/include/search_unit_data.hpp +++ b/include/search_unit_data.hpp @@ -31,6 +31,7 @@ #pragma once #include +#include #include "model.hpp" diff --git a/include/solver.hpp b/include/solver.hpp index 2fd45a31..e2d32f89 100644 --- a/include/solver.hpp +++ b/include/solver.hpp @@ -55,18 +55,18 @@ #include "algorithms/variable_heuristic.hpp" #include "algorithms/variable_candidates_heuristic.hpp" #include "algorithms/value_heuristic.hpp" -#include "algorithms/error_projection_heuristic.hpp" +#include "algorithms/error_projection_algorithm.hpp" #include "algorithms/adaptive_search_variable_heuristic.hpp" #include "algorithms/adaptive_search_variable_candidates_heuristic.hpp" #include "algorithms/adaptive_search_value_heuristic.hpp" -#include "algorithms/adaptive_search_error_projection_heuristic.hpp" +#include "algorithms/adaptive_search_error_projection_algorithm.hpp" #include "algorithms/antidote_search_variable_heuristic.hpp" #include "algorithms/antidote_search_variable_candidates_heuristic.hpp" #include "algorithms/antidote_search_value_heuristic.hpp" -#include "algorithms/culprit_search_error_projection_heuristic.hpp" +#include "algorithms/culprit_search_error_projection_algorithm.hpp" #include "macros.hpp" @@ -139,7 +139,7 @@ namespace ghost std::string _variable_heuristic; std::string _variable_candidates_heuristic; std::string _value_heuristic; - std::string _error_projection_heuristic; + std::string _error_projection_algorithm; // From search_unit_data // Matrix to know which constraints contain a given variable @@ -508,7 +508,7 @@ namespace ghost _variable_heuristic = search_unit.variable_heuristic->get_name(); _variable_candidates_heuristic = search_unit.variable_candidates_heuristic->get_name(); _value_heuristic = search_unit.value_heuristic->get_name(); - _error_projection_heuristic = search_unit.error_projection_heuristic->get_name(); + _error_projection_algorithm = search_unit.error_projection_algorithm->get_name(); _model = std::move( search_unit.transfer_model() ); } @@ -634,7 +634,7 @@ namespace ghost _variable_heuristic = units.at( winning_thread ).variable_heuristic->get_name(); _variable_candidates_heuristic = units.at( winning_thread ).variable_candidates_heuristic->get_name(); _value_heuristic = units.at( winning_thread ).value_heuristic->get_name(); - _error_projection_heuristic = units.at( winning_thread ).error_projection_heuristic->get_name(); + _error_projection_algorithm = units.at( winning_thread ).error_projection_algorithm->get_name(); _model = std::move( units.at( winning_thread ).transfer_model() ); } @@ -670,7 +670,7 @@ namespace ghost _variable_heuristic = units.at( best_non_solution ).variable_heuristic->get_name(); _variable_candidates_heuristic = units.at( best_non_solution ).variable_candidates_heuristic->get_name(); _value_heuristic = units.at( best_non_solution ).value_heuristic->get_name(); - _error_projection_heuristic = units.at( best_non_solution ).error_projection_heuristic->get_name(); + _error_projection_algorithm = units.at( best_non_solution ).error_projection_algorithm->get_name(); _model = std::move( units.at( best_non_solution ).transfer_model() ); } @@ -719,7 +719,7 @@ namespace ghost << "Variable heuristic: " << _variable_heuristic << "\n" << "Variable candidate heuristic: " << _variable_candidates_heuristic << "\n" << "Value heuristic: " << _value_heuristic << "\n" - << "Error projection heuristic: " << _error_projection_heuristic << "\n" + << "Error projection algorithm: " << _error_projection_algorithm << "\n" << "Started from a custom variables assignment: " << std::boolalpha << _options.custom_starting_point << "\n" << "Search resumed from a previous run: " << std::boolalpha << _options.resume_search << "\n" << "Parallel search: " << std::boolalpha << _options.parallel_runs << "\n" diff --git a/src/algorithms/adaptive_search_error_projection_heuristic.cpp b/src/algorithms/adaptive_search_error_projection_algorithm.cpp similarity index 68% rename from src/algorithms/adaptive_search_error_projection_heuristic.cpp rename to src/algorithms/adaptive_search_error_projection_algorithm.cpp index 09d1e7d9..7d760c1d 100644 --- a/src/algorithms/adaptive_search_error_projection_heuristic.cpp +++ b/src/algorithms/adaptive_search_error_projection_algorithm.cpp @@ -27,7 +27,7 @@ * along with GHOST. If not, see http://www.gnu.org/licenses/. */ -#include "algorithms/adaptive_search_error_projection_heuristic.hpp" +#include "algorithms/adaptive_search_error_projection_algorithm.hpp" using ghost::algorithms::AdaptiveSearchErrorProjection; using ghost::Variable; @@ -36,25 +36,23 @@ using ghost::Constraint; AdaptiveSearchErrorProjection::AdaptiveSearchErrorProjection() : ErrorProjection( "Adaptive Search" ) { } - -void AdaptiveSearchErrorProjection::compute_variable_errors( std::vector& error_variables, - const std::vector& variables, - const std::vector>& matrix_var_ctr, - const std::vector>& constraints ) + +void AdaptiveSearchErrorProjection::compute_variable_errors( const std::vector& variables, + const std::vector>& constraints, + SearchUnitData& data ) { - std::fill( error_variables.begin(), error_variables.end(), 0. ); + std::fill( data.error_variables.begin(), data.error_variables.end(), 0. ); for( int variable_id = 0; variable_id < static_cast( variables.size() ); ++variable_id ) - for( int constraint_id : matrix_var_ctr.at( variable_id ) ) - error_variables[ variable_id ] += constraints[ constraint_id ]->_current_error; + for( int constraint_id : data.matrix_var_ctr.at( variable_id ) ) + data.error_variables[ variable_id ] += constraints[ constraint_id ]->_current_error; } -void AdaptiveSearchErrorProjection::update_variable_errors( std::vector& error_variables, - const std::vector& variables, - const std::vector>& matrix_var_ctr, +void AdaptiveSearchErrorProjection::update_variable_errors( const std::vector& variables, std::shared_ptr constraint, + SearchUnitData& data, double delta ) { for( const int variable_id : constraint->get_variable_ids() ) - error_variables[ variable_id ] += delta; + data.error_variables[ variable_id ] += delta; } diff --git a/src/algorithms/culprit_search_error_projection_heuristic.cpp b/src/algorithms/culprit_search_error_projection_algorithm.cpp similarity index 80% rename from src/algorithms/culprit_search_error_projection_heuristic.cpp rename to src/algorithms/culprit_search_error_projection_algorithm.cpp index fe23346f..fc285ba7 100644 --- a/src/algorithms/culprit_search_error_projection_heuristic.cpp +++ b/src/algorithms/culprit_search_error_projection_algorithm.cpp @@ -32,7 +32,7 @@ #include #include -#include "algorithms/culprit_search_error_projection_heuristic.hpp" +#include "algorithms/culprit_search_error_projection_algorithm.hpp" using ghost::algorithms::CulpritSearchErrorProjection; using ghost::Variable; @@ -42,9 +42,9 @@ CulpritSearchErrorProjection::CulpritSearchErrorProjection() : ErrorProjection( "Culprit Search" ) { } -void CulpritSearchErrorProjection::initialize_data_structures() +void CulpritSearchErrorProjection::initialize_data_structures( const SearchUnitData& data ) { - _error_variables_by_constraints = std::vector>( number_constraints, std::vector( number_variables, 0. ) ); + _error_variables_by_constraints = std::vector>( data.number_constraints, std::vector( data.number_variables, 0. ) ); } void CulpritSearchErrorProjection::compute_variable_errors_on_constraint( const std::vector& variables, @@ -109,45 +109,43 @@ void CulpritSearchErrorProjection::compute_variable_errors_on_constraint( const } } -void CulpritSearchErrorProjection::compute_variable_errors( std::vector& error_variables, - const std::vector& variables, - const std::vector>& matrix_var_ctr, - const std::vector>& constraints ) +void CulpritSearchErrorProjection::compute_variable_errors( const std::vector& variables, + const std::vector>& constraints, + SearchUnitData& data ) { - std::fill( error_variables.begin(), error_variables.end(), 0. ); + std::fill( data.error_variables.begin(), data.error_variables.end(), 0. ); for( auto constraint : constraints ) { - compute_variable_errors_on_constraint( variables, matrix_var_ctr, constraint ); + compute_variable_errors_on_constraint( variables, data.matrix_var_ctr, constraint ); // add normalize deltas of the current constraint to the error variables vector. std::transform( _error_variables_by_constraints[ constraint->_id ].cbegin(), _error_variables_by_constraints[ constraint->_id ].cend(), - error_variables.cbegin(), - error_variables.begin(), + data.error_variables.cbegin(), + data.error_variables.begin(), std::plus<>{} ); } } -void CulpritSearchErrorProjection::update_variable_errors( std::vector& error_variables, - const std::vector& variables, - const std::vector>& matrix_var_ctr, +void CulpritSearchErrorProjection::update_variable_errors( const std::vector& variables, std::shared_ptr constraint, + SearchUnitData& data, double delta ) { // remove current deltas of the given constraint to the error variables vector. std::transform( _error_variables_by_constraints[ constraint->_id ].cbegin(), _error_variables_by_constraints[ constraint->_id ].cend(), - error_variables.cbegin(), - error_variables.begin(), + data.error_variables.cbegin(), + data.error_variables.begin(), std::minus<>{} ); - compute_variable_errors_on_constraint( variables, matrix_var_ctr, constraint ); + compute_variable_errors_on_constraint( variables, data.matrix_var_ctr, constraint ); // add normalize deltas of the current constraint to the error variables vector. std::transform( _error_variables_by_constraints[ constraint->_id ].cbegin(), _error_variables_by_constraints[ constraint->_id ].cend(), - error_variables.cbegin(), - error_variables.begin(), + data.error_variables.cbegin(), + data.error_variables.begin(), std::plus<>{} ); } From cf8fa9f30587a457ebaae4020922f708a204f05f Mon Sep 17 00:00:00 2001 From: Florian Richoux Date: Thu, 7 Mar 2024 16:08:41 +0900 Subject: [PATCH 06/11] Fix a small mistake in uniform drawing, and remove the random tabu marking --- include/search_unit.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/search_unit.hpp b/include/search_unit.hpp index 6821d28c..b2514ead 100644 --- a/include/search_unit.hpp +++ b/include/search_unit.hpp @@ -472,7 +472,7 @@ namespace ghost // of chance to escape it and mark the variable as tabu.) void plateau_management( int variable_to_change, int new_value, const std::map< int, std::vector>& delta_errors ) { - if( rng.uniform(0, 100) <= options.percent_chance_escape_plateau ) + if( rng.uniform(1, 100) <= options.percent_chance_escape_plateau ) { data.tabu_list[ variable_to_change ] = options.tabu_time_local_min + data.local_moves; must_compute_variable_candidates = true; @@ -492,7 +492,7 @@ namespace ghost // Otherwise try them first, but with 10% of chance, the solver finally marks the variable as tabu.) void local_minimum_management( int variable_to_change, int new_value, bool no_other_variables_to_try ) { - if( no_other_variables_to_try || rng.uniform(0, 100) <= 10 ) + if( no_other_variables_to_try ) // || rng.uniform(1, 100) <= 10 { data.tabu_list[ variable_to_change ] = options.tabu_time_local_min + data.local_moves; must_compute_variable_candidates = true; From 866ea288766d4ee84684590f1c7e2f0e67b4085f Mon Sep 17 00:00:00 2001 From: Florian Richoux Date: Thu, 7 Mar 2024 17:43:57 +0900 Subject: [PATCH 07/11] Add Random Walk files --- ...random_walk_error_projection_algorithm.hpp | 53 ++++++++++++ .../random_walk_value_heuristic.hpp | 53 ++++++++++++ ...dom_walk_variable_candidates_heuristic.hpp | 48 +++++++++++ .../random_walk_variable_heuristic.hpp | 48 +++++++++++ ...random_walk_error_projection_algorithm.cpp | 49 +++++++++++ .../random_walk_value_heuristic.cpp | 81 +++++++++++++++++++ ...dom_walk_variable_candidates_heuristic.cpp | 60 ++++++++++++++ .../random_walk_variable_heuristic.cpp | 41 ++++++++++ 8 files changed, 433 insertions(+) create mode 100644 include/algorithms/random_walk_error_projection_algorithm.hpp create mode 100644 include/algorithms/random_walk_value_heuristic.hpp create mode 100644 include/algorithms/random_walk_variable_candidates_heuristic.hpp create mode 100644 include/algorithms/random_walk_variable_heuristic.hpp create mode 100644 src/algorithms/random_walk_error_projection_algorithm.cpp create mode 100644 src/algorithms/random_walk_value_heuristic.cpp create mode 100644 src/algorithms/random_walk_variable_candidates_heuristic.cpp create mode 100644 src/algorithms/random_walk_variable_heuristic.cpp diff --git a/include/algorithms/random_walk_error_projection_algorithm.hpp b/include/algorithms/random_walk_error_projection_algorithm.hpp new file mode 100644 index 00000000..7e2c3c20 --- /dev/null +++ b/include/algorithms/random_walk_error_projection_algorithm.hpp @@ -0,0 +1,53 @@ +/* + * GHOST (General meta-Heuristic Optimization Solving Tool) is a C++ framework + * designed to help developers to model and implement optimization problem + * solving. It contains a meta-heuristic solver aiming to solve any kind of + * combinatorial and optimization real-time problems represented by a CSP/COP/EF-CSP/EF-COP. + * + * First developed to solve game-related optimization problems, GHOST can be used for + * any kind of applications where solving combinatorial and optimization problems. In + * particular, it had been designed to be able to solve not-too-complex problem instances + * within some milliseconds, making it very suitable for highly reactive or embedded systems. + * Please visit https://github.com/richoux/GHOST for further information. + * + * Copyright (C) 2014-2024 Florian Richoux + * + * This file is part of GHOST. + * GHOST is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * GHOST is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with GHOST. If not, see http://www.gnu.org/licenses/. + */ + +#pragma once + +#include "error_projection_algorithm.hpp" + +namespace ghost +{ + namespace algorithms + { + class RandomWalkErrorProjection : public ErrorProjection + { + public: + RandomWalkErrorProjection(); + + void compute_variable_errors( const std::vector& variables, + const std::vector>& constraints, + SearchUnitData& data ) override; + + void update_variable_errors( const std::vector& variables, + std::shared_ptr constraint, + SearchUnitData& data, + double delta ) override; + }; + } +} diff --git a/include/algorithms/random_walk_value_heuristic.hpp b/include/algorithms/random_walk_value_heuristic.hpp new file mode 100644 index 00000000..0a4fb26a --- /dev/null +++ b/include/algorithms/random_walk_value_heuristic.hpp @@ -0,0 +1,53 @@ +/* + * GHOST (General meta-Heuristic Optimization Solving Tool) is a C++ framework + * designed to help developers to model and implement optimization problem + * solving. It contains a meta-heuristic solver aiming to solve any kind of + * combinatorial and optimization real-time problems represented by a CSP/COP/EF-CSP/EF-COP. + * + * First developed to solve game-related optimization problems, GHOST can be used for + * any kind of applications where solving combinatorial and optimization problems. In + * particular, it had been designed to be able to solve not-too-complex problem instances + * within some milliseconds, making it very suitable for highly reactive or embedded systems. + * Please visit https://github.com/richoux/GHOST for further information. + * + * Copyright (C) 2014-2024 Florian Richoux + * + * This file is part of GHOST. + * GHOST is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * GHOST is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with GHOST. If not, see http://www.gnu.org/licenses/. + */ + +#pragma once + +#include + +#include "value_heuristic.hpp" + +namespace ghost +{ + namespace algorithms + { + class RandomWalkValueHeuristic : public ValueHeuristic + { + public: + RandomWalkValueHeuristic(); + + int select_value( int variable_to_change, + const SearchUnitData& data, + const Model& model, + const std::map>& delta_errors, + double& min_conflict, + randutils::mt19937_rng& rng ) const override; + }; + } +} diff --git a/include/algorithms/random_walk_variable_candidates_heuristic.hpp b/include/algorithms/random_walk_variable_candidates_heuristic.hpp new file mode 100644 index 00000000..ad21bffb --- /dev/null +++ b/include/algorithms/random_walk_variable_candidates_heuristic.hpp @@ -0,0 +1,48 @@ +/* + * GHOST (General meta-Heuristic Optimization Solving Tool) is a C++ framework + * designed to help developers to model and implement optimization problem + * solving. It contains a meta-heuristic solver aiming to solve any kind of + * combinatorial and optimization real-time problems represented by a CSP/COP/EF-CSP/EF-COP. + * + * First developed to solve game-related optimization problems, GHOST can be used for + * any kind of applications where solving combinatorial and optimization problems. In + * particular, it had been designed to be able to solve not-too-complex problem instances + * within some milliseconds, making it very suitable for highly reactive or embedded systems. + * Please visit https://github.com/richoux/GHOST for further information. + * + * Copyright (C) 2014-2024 Florian Richoux + * + * This file is part of GHOST. + * GHOST is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * GHOST is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with GHOST. If not, see http://www.gnu.org/licenses/. + */ + +#pragma once + +#include + +#include "variable_candidates_heuristic.hpp" + +namespace ghost +{ + namespace algorithms + { + class RandomWalkVariableCandidatesHeuristic : public VariableCandidatesHeuristic + { + public: + RandomWalkVariableCandidatesHeuristic(); + + std::vector compute_variable_candidates( const SearchUnitData& data ) const override; + }; + } +} diff --git a/include/algorithms/random_walk_variable_heuristic.hpp b/include/algorithms/random_walk_variable_heuristic.hpp new file mode 100644 index 00000000..f1a23ae0 --- /dev/null +++ b/include/algorithms/random_walk_variable_heuristic.hpp @@ -0,0 +1,48 @@ +/* + * GHOST (General meta-Heuristic Optimization Solving Tool) is a C++ framework + * designed to help developers to model and implement optimization problem + * solving. It contains a meta-heuristic solver aiming to solve any kind of + * combinatorial and optimization real-time problems represented by a CSP/COP/EF-CSP/EF-COP. + * + * First developed to solve game-related optimization problems, GHOST can be used for + * any kind of applications where solving combinatorial and optimization problems. In + * particular, it had been designed to be able to solve not-too-complex problem instances + * within some milliseconds, making it very suitable for highly reactive or embedded systems. + * Please visit https://github.com/richoux/GHOST for further information. + * + * Copyright (C) 2014-2024 Florian Richoux + * + * This file is part of GHOST. + * GHOST is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * GHOST is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with GHOST. If not, see http://www.gnu.org/licenses/. + */ + +#pragma once + +#include + +#include "variable_heuristic.hpp" + +namespace ghost +{ + namespace algorithms + { + class RandomWalkVariableHeuristic : public VariableHeuristic + { + public: + RandomWalkVariableHeuristic(); + + int select_variable( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const override; + }; + } +} diff --git a/src/algorithms/random_walk_error_projection_algorithm.cpp b/src/algorithms/random_walk_error_projection_algorithm.cpp new file mode 100644 index 00000000..0437003b --- /dev/null +++ b/src/algorithms/random_walk_error_projection_algorithm.cpp @@ -0,0 +1,49 @@ +/* + * GHOST (General meta-Heuristic Optimization Solving Tool) is a C++ framework + * designed to help developers to model and implement optimization problem + * solving. It contains a meta-heuristic solver aiming to solve any kind of + * combinatorial and optimization real-time problems represented by a CSP/COP/EF-CSP/EF-COP. + * + * First developed to solve game-related optimization problems, GHOST can be used for + * any kind of applications where solving combinatorial and optimization problems. In + * particular, it had been designed to be able to solve not-too-complex problem instances + * within some milliseconds, making it very suitable for highly reactive or embedded systems. + * Please visit https://github.com/richoux/GHOST for further information. + * + * Copyright (C) 2014-2024 Florian Richoux + * + * This file is part of GHOST. + * GHOST is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * GHOST is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with GHOST. If not, see http://www.gnu.org/licenses/. + */ + +#include "algorithms/null_error_projection_algorithm.hpp" + +using ghost::algorithms::NullErrorProjectionErrorProjection; +using ghost::Variable; +using ghost::Constraint; + +NullErrorProjection::NullErrorProjectionErrorProjection() + : ErrorProjection( "Null Error Projection" ) +{ } + +void NullErrorProjectionErrorProjection::compute_variable_errors( const std::vector& variables, + const std::vector>& constraints, + SearchUnitData& data ) +{} + +void NullErrorProjectionErrorProjection::update_variable_errors( const std::vector& variables, + std::shared_ptr constraint, + SearchUnitData& data, + double delta ) +{} diff --git a/src/algorithms/random_walk_value_heuristic.cpp b/src/algorithms/random_walk_value_heuristic.cpp new file mode 100644 index 00000000..6aae904f --- /dev/null +++ b/src/algorithms/random_walk_value_heuristic.cpp @@ -0,0 +1,81 @@ +/* + * GHOST (General meta-Heuristic Optimization Solving Tool) is a C++ framework + * designed to help developers to model and implement optimization problem + * solving. It contains a meta-heuristic solver aiming to solve any kind of + * combinatorial and optimization real-time problems represented by a CSP/COP/EF-CSP/EF-COP. + * + * First developed to solve game-related optimization problems, GHOST can be used for + * any kind of applications where solving combinatorial and optimization problems. In + * particular, it had been designed to be able to solve not-too-complex problem instances + * within some milliseconds, making it very suitable for highly reactive or embedded systems. + * Please visit https://github.com/richoux/GHOST for further information. + * + * Copyright (C) 2014-2024 Florian Richoux + * + * This file is part of GHOST. + * GHOST is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * GHOST is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with GHOST. If not, see http://www.gnu.org/licenses/. + */ + +#include +#include + +#include "algorithms/random_walk_value_heuristic.hpp" + +using ghost::algorithms::RandomWalkValueHeuristic; +using ghost::SearchUnitData; +using ghost::Model; + +RandomWalkValueHeuristic::RandomWalkValueHeuristic() + : ValueHeuristic( "Random Walk" ) +{ } + +int RandomWalkValueHeuristic::select_value( int variable_to_change, + const SearchUnitData& data, + const Model& model, + const std::map>& delta_errors, + double& min_conflict, + randutils::mt19937_rng& rng ) const +{ + std::vector candidate_values; + std::map cumulated_delta_errors; + for( const auto& deltas : delta_errors ) + cumulated_delta_errors[ deltas.first ] = std::accumulate( deltas.second.begin(), deltas.second.end(), 0.0 ); + + for( const auto& deltas : cumulated_delta_errors ) + { + if( min_conflict > deltas.second ) + { + candidate_values.clear(); + candidate_values.push_back( deltas.first ); + min_conflict = deltas.second; + } + else + if( min_conflict == deltas.second ) + candidate_values.push_back( deltas.first ); + } + + if( candidate_values.empty() ) + return variable_to_change; + + // if we deal with an optimization problem, find the value minimizing to objective function + if( data.is_optimization ) + { + if( model.permutation_problem ) + return static_cast( model.objective->heuristic_value_permutation( variable_to_change, candidate_values, rng ) ); + else + return model.objective->heuristic_value( variable_to_change, candidate_values, rng ); + } + else + return rng.pick( candidate_values ); +} diff --git a/src/algorithms/random_walk_variable_candidates_heuristic.cpp b/src/algorithms/random_walk_variable_candidates_heuristic.cpp new file mode 100644 index 00000000..d58829d8 --- /dev/null +++ b/src/algorithms/random_walk_variable_candidates_heuristic.cpp @@ -0,0 +1,60 @@ +/* + * GHOST (General meta-Heuristic Optimization Solving Tool) is a C++ framework + * designed to help developers to model and implement optimization problem + * solving. It contains a meta-heuristic solver aiming to solve any kind of + * combinatorial and optimization real-time problems represented by a CSP/COP/EF-CSP/EF-COP. + * + * First developed to solve game-related optimization problems, GHOST can be used for + * any kind of applications where solving combinatorial and optimization problems. In + * particular, it had been designed to be able to solve not-too-complex problem instances + * within some milliseconds, making it very suitable for highly reactive or embedded systems. + * Please visit https://github.com/richoux/GHOST for further information. + * + * Copyright (C) 2014-2024 Florian Richoux + * + * This file is part of GHOST. + * GHOST is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * GHOST is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with GHOST. If not, see http://www.gnu.org/licenses/. + */ + +#include "algorithms/adaptive_search_variable_candidates_heuristic.hpp" + +using ghost::algorithms::AdaptiveSearchVariableCandidatesHeuristic; + +AdaptiveSearchVariableCandidatesHeuristic::AdaptiveSearchVariableCandidatesHeuristic() + : VariableCandidatesHeuristic( "Adaptive Search" ) +{ } + +std::vector AdaptiveSearchVariableCandidatesHeuristic::compute_variable_candidates( const SearchUnitData& data ) const +{ + std::vector worst_variables_list; + double worst_variable_cost = -1; + + for( int variable_id = 0; variable_id < data.number_variables; ++variable_id ) + if( worst_variable_cost <= data.error_variables[ variable_id ] + && data.tabu_list[ variable_id ] <= data.local_moves + && ( !data.matrix_var_ctr.at( variable_id ).empty() || ( data.is_optimization && data.current_sat_error == 0 ) ) ) + { + if( worst_variable_cost < data.error_variables[ variable_id ] ) + { + worst_variables_list.clear(); + worst_variables_list.push_back( variable_id ); + worst_variable_cost = data.error_variables[ variable_id ]; + } + else + if( worst_variable_cost == data.error_variables[ variable_id ] ) + worst_variables_list.push_back( variable_id ); + } + + return worst_variables_list; +} diff --git a/src/algorithms/random_walk_variable_heuristic.cpp b/src/algorithms/random_walk_variable_heuristic.cpp new file mode 100644 index 00000000..54eb8a88 --- /dev/null +++ b/src/algorithms/random_walk_variable_heuristic.cpp @@ -0,0 +1,41 @@ +/* + * GHOST (General meta-Heuristic Optimization Solving Tool) is a C++ framework + * designed to help developers to model and implement optimization problem + * solving. It contains a meta-heuristic solver aiming to solve any kind of + * combinatorial and optimization real-time problems represented by a CSP/COP/EF-CSP/EF-COP. + * + * First developed to solve game-related optimization problems, GHOST can be used for + * any kind of applications where solving combinatorial and optimization problems. In + * particular, it had been designed to be able to solve not-too-complex problem instances + * within some milliseconds, making it very suitable for highly reactive or embedded systems. + * Please visit https://github.com/richoux/GHOST for further information. + * + * Copyright (C) 2014-2024 Florian Richoux + * + * This file is part of GHOST. + * GHOST is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * GHOST is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with GHOST. If not, see http://www.gnu.org/licenses/. + */ + +#include "algorithms/adaptive_search_variable_heuristic.hpp" + +using ghost::algorithms::AdaptiveSearchVariableHeuristic; + +AdaptiveSearchVariableHeuristic::AdaptiveSearchVariableHeuristic() + : VariableHeuristic( "Adaptive Search" ) +{ } + +int AdaptiveSearchVariableHeuristic::select_variable( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const +{ + return static_cast( rng.pick( candidates ) ); +} From 5e98f94957aa0783adc58e60f23798b544bdbcdf Mon Sep 17 00:00:00 2001 From: Florian Richoux Date: Mon, 11 Mar 2024 09:00:54 +0900 Subject: [PATCH 08/11] Algorithms for Random Walk --- CMakeLists.txt | 14 ++++++-- ...pp => null_error_projection_algorithm.hpp} | 4 +-- ...pp => null_error_projection_algorithm.cpp} | 20 +++++------ .../random_walk_value_heuristic.cpp | 34 ++----------------- ...dom_walk_variable_candidates_heuristic.cpp | 33 +++++------------- .../random_walk_variable_heuristic.cpp | 10 +++--- 6 files changed, 39 insertions(+), 76 deletions(-) rename include/algorithms/{random_walk_error_projection_algorithm.hpp => null_error_projection_algorithm.hpp} (95%) rename src/algorithms/{random_walk_error_projection_algorithm.cpp => null_error_projection_algorithm.cpp} (63%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ee28e2a7..aa4c369f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,7 +109,11 @@ set(libHeadersAlgorithmsList "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/antidote_search_variable_heuristic.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/antidote_search_variable_candidates_heuristic.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/antidote_search_value_heuristic.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/culprit_search_error_projection_algorithm.hpp") + "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/culprit_search_error_projection_algorithm.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/random_walk_variable_heuristic.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/random_walk_variable_candidates_heuristic.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/random_walk_value_heuristic.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/null_error_projection_algorithm.hpp") set(libHeadersGlobalConstraintsList "${CMAKE_CURRENT_SOURCE_DIR}/include/global_constraints/all_different.hpp" @@ -146,6 +150,10 @@ set(toAddInLibs src/algorithms/antidote_search_variable_candidates_heuristic.cpp src/algorithms/antidote_search_value_heuristic.cpp src/algorithms/culprit_search_error_projection_algorithm.cpp + src/algorithms/random_walk_variable_heuristic.cpp + src/algorithms/random_walk_variable_candidates_heuristic.cpp + src/algorithms/random_walk_value_heuristic.cpp + src/algorithms/null_error_projection_algorithm.cpp src/global_constraints/all_different.cpp src/global_constraints/all_equal.cpp src/global_constraints/fix_value.cpp @@ -199,8 +207,8 @@ endif() 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 "8") +set (CPACK_PACKAGE_VERSION_MAJOR "3") +set (CPACK_PACKAGE_VERSION_MINOR "0") set (CPACK_PACKAGE_VERSION_PATCH "2") set (CPACK_PACKAGE_CONTACT "florian.richoux@polytechnique.edu") set (CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) diff --git a/include/algorithms/random_walk_error_projection_algorithm.hpp b/include/algorithms/null_error_projection_algorithm.hpp similarity index 95% rename from include/algorithms/random_walk_error_projection_algorithm.hpp rename to include/algorithms/null_error_projection_algorithm.hpp index 7e2c3c20..382fc087 100644 --- a/include/algorithms/random_walk_error_projection_algorithm.hpp +++ b/include/algorithms/null_error_projection_algorithm.hpp @@ -35,10 +35,10 @@ namespace ghost { namespace algorithms { - class RandomWalkErrorProjection : public ErrorProjection + class NullErrorProjection : public ErrorProjection { public: - RandomWalkErrorProjection(); + NullErrorProjection(); void compute_variable_errors( const std::vector& variables, const std::vector>& constraints, diff --git a/src/algorithms/random_walk_error_projection_algorithm.cpp b/src/algorithms/null_error_projection_algorithm.cpp similarity index 63% rename from src/algorithms/random_walk_error_projection_algorithm.cpp rename to src/algorithms/null_error_projection_algorithm.cpp index 0437003b..5c882758 100644 --- a/src/algorithms/random_walk_error_projection_algorithm.cpp +++ b/src/algorithms/null_error_projection_algorithm.cpp @@ -29,21 +29,21 @@ #include "algorithms/null_error_projection_algorithm.hpp" -using ghost::algorithms::NullErrorProjectionErrorProjection; +using ghost::algorithms::NullErrorProjection; using ghost::Variable; using ghost::Constraint; -NullErrorProjection::NullErrorProjectionErrorProjection() +NullErrorProjection::NullErrorProjection() : ErrorProjection( "Null Error Projection" ) -{ } +{} -void NullErrorProjectionErrorProjection::compute_variable_errors( const std::vector& variables, - const std::vector>& constraints, - SearchUnitData& data ) +void NullErrorProjection::compute_variable_errors( const std::vector& variables, + const std::vector>& constraints, + SearchUnitData& data ) {} -void NullErrorProjectionErrorProjection::update_variable_errors( const std::vector& variables, - std::shared_ptr constraint, - SearchUnitData& data, - double delta ) +void NullErrorProjection::update_variable_errors( const std::vector& variables, + std::shared_ptr constraint, + SearchUnitData& data, + double delta ) {} diff --git a/src/algorithms/random_walk_value_heuristic.cpp b/src/algorithms/random_walk_value_heuristic.cpp index 6aae904f..bbd733bd 100644 --- a/src/algorithms/random_walk_value_heuristic.cpp +++ b/src/algorithms/random_walk_value_heuristic.cpp @@ -47,35 +47,7 @@ int RandomWalkValueHeuristic::select_value( int variable_to_change, double& min_conflict, randutils::mt19937_rng& rng ) const { - std::vector candidate_values; - std::map cumulated_delta_errors; - for( const auto& deltas : delta_errors ) - cumulated_delta_errors[ deltas.first ] = std::accumulate( deltas.second.begin(), deltas.second.end(), 0.0 ); - - for( const auto& deltas : cumulated_delta_errors ) - { - if( min_conflict > deltas.second ) - { - candidate_values.clear(); - candidate_values.push_back( deltas.first ); - min_conflict = deltas.second; - } - else - if( min_conflict == deltas.second ) - candidate_values.push_back( deltas.first ); - } - - if( candidate_values.empty() ) - return variable_to_change; - - // if we deal with an optimization problem, find the value minimizing to objective function - if( data.is_optimization ) - { - if( model.permutation_problem ) - return static_cast( model.objective->heuristic_value_permutation( variable_to_change, candidate_values, rng ) ); - else - return model.objective->heuristic_value( variable_to_change, candidate_values, rng ); - } - else - return rng.pick( candidate_values ); + auto pick_value_and_errors = static_cast>>( rng.pick( delta_errors ) ); + min_conflict = std::accumulate( pick_value_and_errors.second.begin(), pick_value_and_errors.second.end(), 0.0 ); + return pick_value_and_errors.first; } diff --git a/src/algorithms/random_walk_variable_candidates_heuristic.cpp b/src/algorithms/random_walk_variable_candidates_heuristic.cpp index d58829d8..1d9432a3 100644 --- a/src/algorithms/random_walk_variable_candidates_heuristic.cpp +++ b/src/algorithms/random_walk_variable_candidates_heuristic.cpp @@ -27,34 +27,17 @@ * along with GHOST. If not, see http://www.gnu.org/licenses/. */ -#include "algorithms/adaptive_search_variable_candidates_heuristic.hpp" +#include "algorithms/random_walk_variable_candidates_heuristic.hpp" -using ghost::algorithms::AdaptiveSearchVariableCandidatesHeuristic; +using ghost::algorithms::RandomWalkVariableCandidatesHeuristic; -AdaptiveSearchVariableCandidatesHeuristic::AdaptiveSearchVariableCandidatesHeuristic() - : VariableCandidatesHeuristic( "Adaptive Search" ) +RandomWalkVariableCandidatesHeuristic::RandomWalkVariableCandidatesHeuristic() + : VariableCandidatesHeuristic( "Random Walk" ) { } -std::vector AdaptiveSearchVariableCandidatesHeuristic::compute_variable_candidates( const SearchUnitData& data ) const +std::vector RandomWalkVariableCandidatesHeuristic::compute_variable_candidates( const SearchUnitData& data ) const { - std::vector worst_variables_list; - double worst_variable_cost = -1; - - for( int variable_id = 0; variable_id < data.number_variables; ++variable_id ) - if( worst_variable_cost <= data.error_variables[ variable_id ] - && data.tabu_list[ variable_id ] <= data.local_moves - && ( !data.matrix_var_ctr.at( variable_id ).empty() || ( data.is_optimization && data.current_sat_error == 0 ) ) ) - { - if( worst_variable_cost < data.error_variables[ variable_id ] ) - { - worst_variables_list.clear(); - worst_variables_list.push_back( variable_id ); - worst_variable_cost = data.error_variables[ variable_id ]; - } - else - if( worst_variable_cost == data.error_variables[ variable_id ] ) - worst_variables_list.push_back( variable_id ); - } - - return worst_variables_list; + std::vector full_variables_list(data.number_variables); + std::iota( full_variables_list.begin(), full_variables_list.end(), 0.0 ); + return full_variables_list; } diff --git a/src/algorithms/random_walk_variable_heuristic.cpp b/src/algorithms/random_walk_variable_heuristic.cpp index 54eb8a88..92467c9f 100644 --- a/src/algorithms/random_walk_variable_heuristic.cpp +++ b/src/algorithms/random_walk_variable_heuristic.cpp @@ -27,15 +27,15 @@ * along with GHOST. If not, see http://www.gnu.org/licenses/. */ -#include "algorithms/adaptive_search_variable_heuristic.hpp" +#include "algorithms/random_walk_variable_heuristic.hpp" -using ghost::algorithms::AdaptiveSearchVariableHeuristic; +using ghost::algorithms::RandomWalkVariableHeuristic; -AdaptiveSearchVariableHeuristic::AdaptiveSearchVariableHeuristic() - : VariableHeuristic( "Adaptive Search" ) +RandomWalkVariableHeuristic::RandomWalkVariableHeuristic() + : VariableHeuristic( "Random Walk" ) { } -int AdaptiveSearchVariableHeuristic::select_variable( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const +int RandomWalkVariableHeuristic::select_variable( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const { return static_cast( rng.pick( candidates ) ); } From 58c36cf95c7efa7c95732fa49a881271a71743c8 Mon Sep 17 00:00:00 2001 From: Florian Richoux Date: Mon, 11 Mar 2024 11:58:00 +0900 Subject: [PATCH 09/11] Finish integrating Random Walks --- include/macros.hpp | 4 ++ include/search_unit.hpp | 106 +++++++++++++++++++++++++++++++--------- include/solver.hpp | 33 ++++++++++++- 3 files changed, 118 insertions(+), 25 deletions(-) diff --git a/include/macros.hpp b/include/macros.hpp index 748e8c2d..c819b532 100644 --- a/include/macros.hpp +++ b/include/macros.hpp @@ -37,3 +37,7 @@ #else #define COUT std::cout #endif + +#if defined GHOST_RANDOM_WALK +#define GHOST_TRACE +#endif diff --git a/include/search_unit.hpp b/include/search_unit.hpp index b2514ead..c5675320 100644 --- a/include/search_unit.hpp +++ b/include/search_unit.hpp @@ -67,6 +67,13 @@ #include "algorithms/culprit_search_error_projection_algorithm.hpp" +#if defined GHOST_RANDOM_WALK +#include "algorithms/random_walk_variable_heuristic.hpp" +#include "algorithms/random_walk_variable_candidates_heuristic.hpp" +#include "algorithms/random_walk_value_heuristic.hpp" +#include "algorithms/null_error_projection_algorithm.hpp" +#endif + #include "macros.hpp" namespace ghost @@ -805,7 +812,6 @@ namespace ghost // Select the next current configuration (local move) double min_conflict = std::numeric_limits::max(); int new_value = value_heuristic->select_value( variable_to_change, data, model, delta_errors, min_conflict, rng ); - #if defined GHOST_TRACE std::vector candidate_values; @@ -830,21 +836,31 @@ namespace ghost << ": " << cumulated_delta_errors[ deltas.first ] << "\n"; } else - if( value_heuristic->get_name().compare( "Antidote Search" ) == 0 ) + if( value_heuristic->get_name().compare( "Random Walk" ) == 0 ) { - double transformed = cumulated_delta_errors_antidote[ index ] >= 0 ? 0.0 : -cumulated_delta_errors_antidote[ index ]; - COUT << "(Antidote Search Value Heuristic) Error for switching var[" << variable_to_change << "]=" << model.variables[ variable_to_change ].get_value() + COUT << "(Random Walk Value Heuristic) Error for switching var[" << variable_to_change << "]=" << model.variables[ variable_to_change ].get_value() << " with var[" << deltas.first << "]=" << model.variables[ deltas.first ].get_value() - << ": " << cumulated_delta_errors_antidote[ index ] << ", transformed: " << transformed << "\n"; + << ": " << cumulated_delta_errors[ deltas.first ] << "\n"; } + else + if( value_heuristic->get_name().compare( "Antidote Search" ) == 0 ) + { + double transformed = cumulated_delta_errors_antidote[ index ] >= 0 ? 0.0 : -cumulated_delta_errors_antidote[ index ]; + COUT << "(Antidote Search Value Heuristic) Error for switching var[" << variable_to_change << "]=" << model.variables[ variable_to_change ].get_value() + << " with var[" << deltas.first << "]=" << model.variables[ deltas.first ].get_value() + << ": " << cumulated_delta_errors_antidote[ index ] << ", transformed: " << transformed << "\n"; + } } else { if( value_heuristic->get_name().compare( "Adaptive Search" ) == 0 ) COUT << "(Adaptive Search Value Heuristic) Error for the value " << deltas.first << ": " << cumulated_delta_errors[ deltas.first ] << "\n"; else - if( value_heuristic->get_name().compare( "Antidote Search" ) == 0 ) - COUT << "(Antidote Search Value Heuristic) Error for the value " << deltas.first << ": " << cumulated_delta_errors_antidote[ index ] << "\n"; + if( value_heuristic->get_name().compare( "Random Walk" ) == 0 ) + COUT << "(Random Walk Value Heuristic) Error for the value " << deltas.first << ": " << cumulated_delta_errors[ deltas.first ] << "\n"; + else + if( value_heuristic->get_name().compare( "Antidote Search" ) == 0 ) + COUT << "(Antidote Search Value Heuristic) Error for the value " << deltas.first << ": " << cumulated_delta_errors_antidote[ index ] << "\n"; } ++index; } @@ -853,17 +869,19 @@ namespace ghost cumulated_delta_errors_antidote.end(), cumulated_delta_errors_for_distribution.begin(), []( auto delta ){ if( delta >= 0) return 0.0; else return -delta; } ); - + + auto min_conflict_copy = min_conflict; for( const auto& deltas : cumulated_delta_errors ) { - if( min_conflict > deltas.second ) + // Should not happen, except for Random Walks. min_conflict is supposed to be, well, the min conflict. + if( min_conflict_copy > deltas.second ) { candidate_values.clear(); candidate_values.push_back( deltas.first ); - min_conflict = deltas.second; + min_conflict_copy = deltas.second; } else - if( min_conflict == deltas.second ) + if( min_conflict_copy == deltas.second ) candidate_values.push_back( deltas.first ); } @@ -875,20 +893,28 @@ namespace ghost COUT << "\n"; } else - if( value_heuristic->get_name().compare( "Antidote Search" ) == 0 ) - { - auto distrib_value = std::discrete_distribution( cumulated_delta_errors_for_distribution.begin(), cumulated_delta_errors_for_distribution.end() ); - std::vector vec_value( domain_to_explore.size(), 0 ); - for( int n = 0 ; n < 10000 ; ++n ) - ++vec_value[ rng.variate( distrib_value ) ]; - std::vector> vec_value_pair( domain_to_explore.size() ); - for( int n = 0 ; n < domain_to_explore.size() ; ++n ) - vec_value_pair[n] = std::make_pair( cumulated_delta_errors_variable_index_correspondance[n], vec_value[n] ); - std::sort( vec_value_pair.begin(), vec_value_pair.end(), [&](std::pair &a, std::pair &b){ return a.second > b.second; } ); - COUT << "\n(Antidote Search Value Heuristic) Cumulated delta error distribution (normalized):\n"; - for( int n = 0 ; n < domain_to_explore.size() ; ++n ) - COUT << "value " << vec_value_pair[ n ].first << " => " << std::fixed << std::setprecision(3) << static_cast( vec_value_pair[ n ].second ) / 10000 << "\n"; + if( value_heuristic->get_name().compare( "Random Walk" ) == 0 ) + { + COUT << "(Random Walk Value Heuristic) Min conflict value candidates list: " << candidate_values[0]; + for( int i = 1 ; i < static_cast( candidate_values.size() ); ++i ) + COUT << ", " << candidate_values[i]; + COUT << "\n"; } + else + if( value_heuristic->get_name().compare( "Antidote Search" ) == 0 ) + { + auto distrib_value = std::discrete_distribution( cumulated_delta_errors_for_distribution.begin(), cumulated_delta_errors_for_distribution.end() ); + std::vector vec_value( domain_to_explore.size(), 0 ); + for( int n = 0 ; n < 10000 ; ++n ) + ++vec_value[ rng.variate( distrib_value ) ]; + std::vector> vec_value_pair( domain_to_explore.size() ); + for( int n = 0 ; n < domain_to_explore.size() ; ++n ) + vec_value_pair[n] = std::make_pair( cumulated_delta_errors_variable_index_correspondance[n], vec_value[n] ); + std::sort( vec_value_pair.begin(), vec_value_pair.end(), [&](std::pair &a, std::pair &b){ return a.second > b.second; } ); + COUT << "\n(Antidote Search Value Heuristic) Cumulated delta error distribution (normalized):\n"; + for( int n = 0 ; n < domain_to_explore.size() ; ++n ) + COUT << "value " << vec_value_pair[ n ].first << " => " << std::fixed << std::setprecision(3) << static_cast( vec_value_pair[ n ].second ) / 10000 << "\n"; + } if( model.permutation_problem ) COUT << "\nPicked variable index for min conflict: " @@ -901,6 +927,38 @@ namespace ghost #endif // GHOST_TRACE +#if defined GHOST_RANDOM_WALK + local_move( variable_to_change, new_value, min_conflict, delta_errors ); + if( data.is_optimization ) + data.current_opt_cost = model.objective->cost(); + if( data.best_sat_error > data.current_sat_error ) + { +#if defined GHOST_TRACE + COUT << "Best satisfaction error so far (in an optimization problem). Before: " << data.best_sat_error << ", now: " << data.current_sat_error << "\n"; +#endif + data.best_sat_error = data.current_sat_error; + std::transform( model.variables.begin(), + model.variables.end(), + final_solution.begin(), + [&](auto& var){ return var.get_value(); } ); + } + else + if( data.is_optimization && data.current_sat_error == 0.0 && data.best_opt_cost > data.current_opt_cost ) + { +#if defined GHOST_TRACE + COUT << "Best objective function value so far. Before: " << data.best_opt_cost << ", now: " << data.current_opt_cost << "\n"; +#endif + data.best_opt_cost = data.current_opt_cost; + std::transform( model.variables.begin(), + model.variables.end(), + final_solution.begin(), + [&](auto& var){ return var.get_value(); } ); + } + + elapsed_time = std::chrono::steady_clock::now() - start; + continue; +#endif + /**************************************** * 3. Error improved => make local move * ****************************************/ diff --git a/include/solver.hpp b/include/solver.hpp index e2d32f89..65c360d2 100644 --- a/include/solver.hpp +++ b/include/solver.hpp @@ -68,6 +68,13 @@ #include "algorithms/culprit_search_error_projection_algorithm.hpp" +#if defined GHOST_RANDOM_WALK +#include "algorithms/random_walk_variable_heuristic.hpp" +#include "algorithms/random_walk_variable_candidates_heuristic.hpp" +#include "algorithms/random_walk_value_heuristic.hpp" +#include "algorithms/null_error_projection_algorithm.hpp" +#endif + #include "macros.hpp" namespace ghost @@ -463,6 +470,13 @@ namespace ghost if( _options.number_start_samplings < 0 ) _options.number_start_samplings = 10; +#if defined GHOST_RANDOM_WALK + _options.percent_chance_escape_plateau = 0; + _options.tabu_time_local_min = 0; + _options.tabu_time_selected = 0; + _options.number_start_samplings = 1; +#endif + double chrono_search; double chrono_full_computation; @@ -483,9 +497,17 @@ namespace ghost // sequential runs if( is_sequential ) { +#if defined GHOST_RANDOM_WALK + SearchUnit search_unit( _model_builder.build_model(), + _options, + std::make_unique(), + std::make_unique(), + std::make_unique(), + std::make_unique() ); +#else SearchUnit search_unit( _model_builder.build_model(), _options ); - +#endif is_optimization = search_unit.data.is_optimization; std::future unit_future = search_unit.solution_found.get_future(); @@ -521,8 +543,17 @@ namespace ghost for( int i = 0 ; i < _options.number_threads; ++i ) { // Instantiate one model per thread +#if defined GHOST_RANDOM_WALK + units.emplace_back( _model_builder.build_model(), + _options, + std::make_unique(), + std::make_unique(), + std::make_unique(), + std::make_unique() ); +#else units.emplace_back( _model_builder.build_model(), _options ); +#endif } is_optimization = units[0].data.is_optimization; From 339f3f1572459a9420938805b02441fd3820574c Mon Sep 17 00:00:00 2001 From: Florian Richoux Date: Mon, 11 Mar 2024 14:26:37 +0900 Subject: [PATCH 10/11] Minor change in commentaries --- include/search_unit.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/search_unit.hpp b/include/search_unit.hpp index c5675320..b8ceb39b 100644 --- a/include/search_unit.hpp +++ b/include/search_unit.hpp @@ -496,10 +496,10 @@ namespace ghost } // C. local minimum management (if there are no other worst variables to try, mark the variable as tabu. - // Otherwise try them first, but with 10% of chance, the solver finally marks the variable as tabu.) + // Otherwise try them first.) void local_minimum_management( int variable_to_change, int new_value, bool no_other_variables_to_try ) { - if( no_other_variables_to_try ) // || rng.uniform(1, 100) <= 10 + if( no_other_variables_to_try ) // || rng.uniform(1, 100) <= 10 //10% chance to force tabu-marking even if there are other variables to explore. { data.tabu_list[ variable_to_change ] = options.tabu_time_local_min + data.local_moves; must_compute_variable_candidates = true; From 8ea77f802e87831ef259a04858cf5cc86de0024b Mon Sep 17 00:00:00 2001 From: Florian Richoux Date: Mon, 11 Mar 2024 16:55:23 +0900 Subject: [PATCH 11/11] Imnplement Hill Climbing --- CMakeLists.txt | 14 ++--- ChangeLog.md | 4 ++ README.md | 4 +- .../adaptive_search_variable_heuristic.hpp | 48 ---------------- ...ll_free_variable_candidates_heuristic.hpp} | 4 +- ...tic.hpp => uniform_variable_heuristic.hpp} | 4 +- include/macros.hpp | 4 ++ include/search_unit.hpp | 56 +++++++++++-------- include/solver.hpp | 40 +++++++++---- .../adaptive_search_variable_heuristic.cpp | 41 -------------- ...ll_free_variable_candidates_heuristic.cpp} | 19 ++++--- ...tic.cpp => uniform_variable_heuristic.cpp} | 10 ++-- 12 files changed, 97 insertions(+), 151 deletions(-) delete mode 100644 include/algorithms/adaptive_search_variable_heuristic.hpp rename include/algorithms/{random_walk_variable_candidates_heuristic.hpp => all_free_variable_candidates_heuristic.hpp} (93%) rename include/algorithms/{random_walk_variable_heuristic.hpp => uniform_variable_heuristic.hpp} (94%) delete mode 100644 src/algorithms/adaptive_search_variable_heuristic.cpp rename src/algorithms/{random_walk_variable_candidates_heuristic.cpp => all_free_variable_candidates_heuristic.cpp} (70%) rename src/algorithms/{random_walk_variable_heuristic.cpp => uniform_variable_heuristic.cpp} (80%) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa4c369f..e125ad32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,7 +102,6 @@ set(libHeadersAlgorithmsList "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/variable_candidates_heuristic.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/value_heuristic.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/error_projection_algorithm.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/adaptive_search_variable_heuristic.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/adaptive_search_variable_candidates_heuristic.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/adaptive_search_value_heuristic.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/adaptive_search_error_projection_algorithm.hpp" @@ -110,8 +109,8 @@ set(libHeadersAlgorithmsList "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/antidote_search_variable_candidates_heuristic.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/antidote_search_value_heuristic.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/culprit_search_error_projection_algorithm.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/random_walk_variable_heuristic.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/random_walk_variable_candidates_heuristic.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/uniform_variable_heuristic.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/all_free_variable_candidates_heuristic.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/random_walk_value_heuristic.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/algorithms/null_error_projection_algorithm.hpp") @@ -142,7 +141,6 @@ set(toAddInLibs src/model_builder.cpp src/options.cpp src/print.cpp - src/algorithms/adaptive_search_variable_heuristic.cpp src/algorithms/adaptive_search_variable_candidates_heuristic.cpp src/algorithms/adaptive_search_value_heuristic.cpp src/algorithms/adaptive_search_error_projection_algorithm.cpp @@ -150,8 +148,8 @@ set(toAddInLibs src/algorithms/antidote_search_variable_candidates_heuristic.cpp src/algorithms/antidote_search_value_heuristic.cpp src/algorithms/culprit_search_error_projection_algorithm.cpp - src/algorithms/random_walk_variable_heuristic.cpp - src/algorithms/random_walk_variable_candidates_heuristic.cpp + src/algorithms/uniform_variable_heuristic.cpp + src/algorithms/all_free_variable_candidates_heuristic.cpp src/algorithms/random_walk_value_heuristic.cpp src/algorithms/null_error_projection_algorithm.cpp src/global_constraints/all_different.cpp @@ -208,8 +206,8 @@ include (InstallRequiredSystemLibraries) set (CPACK_PACKAGE_NAME "GHOST") set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") set (CPACK_PACKAGE_VERSION_MAJOR "3") -set (CPACK_PACKAGE_VERSION_MINOR "0") -set (CPACK_PACKAGE_VERSION_PATCH "2") +set (CPACK_PACKAGE_VERSION_MINOR "1") +set (CPACK_PACKAGE_VERSION_PATCH "0") set (CPACK_PACKAGE_CONTACT "florian.richoux@polytechnique.edu") set (CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) include (CPack) diff --git a/ChangeLog.md b/ChangeLog.md index 89025f46..08ab8faf 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file, since GHOST 2.0.0. +## [3.1.0] - 2024-03-11 +- Add Random Walk and Hill Climbing as search algorithms, for landscape analysis. +- Minor changes in the global solver algorithm, such as removing the probability to force tabu-marking a variable. + ## [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. diff --git a/README.md b/README.md index 8187d604..a39ede28 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ![](https://github.com/richoux/GHOST/wiki/images/GHOST_banner.png) -[![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) +[![3.1.0](https://img.shields.io/badge/stable-3.1.0-brightgreen.svg)](https://github.com/richoux/GHOST/releases/tag/3.1.0) +[![3.1.x](https://img.shields.io/badge/latest-3.1.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) diff --git a/include/algorithms/adaptive_search_variable_heuristic.hpp b/include/algorithms/adaptive_search_variable_heuristic.hpp deleted file mode 100644 index 85a323a4..00000000 --- a/include/algorithms/adaptive_search_variable_heuristic.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * GHOST (General meta-Heuristic Optimization Solving Tool) is a C++ framework - * designed to help developers to model and implement optimization problem - * solving. It contains a meta-heuristic solver aiming to solve any kind of - * combinatorial and optimization real-time problems represented by a CSP/COP/EF-CSP/EF-COP. - * - * First developed to solve game-related optimization problems, GHOST can be used for - * any kind of applications where solving combinatorial and optimization problems. In - * particular, it had been designed to be able to solve not-too-complex problem instances - * within some milliseconds, making it very suitable for highly reactive or embedded systems. - * Please visit https://github.com/richoux/GHOST for further information. - * - * Copyright (C) 2014-2024 Florian Richoux - * - * This file is part of GHOST. - * GHOST is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * GHOST is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with GHOST. If not, see http://www.gnu.org/licenses/. - */ - -#pragma once - -#include - -#include "variable_heuristic.hpp" - -namespace ghost -{ - namespace algorithms - { - class AdaptiveSearchVariableHeuristic : public VariableHeuristic - { - public: - AdaptiveSearchVariableHeuristic(); - - int select_variable( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const override; - }; - } -} diff --git a/include/algorithms/random_walk_variable_candidates_heuristic.hpp b/include/algorithms/all_free_variable_candidates_heuristic.hpp similarity index 93% rename from include/algorithms/random_walk_variable_candidates_heuristic.hpp rename to include/algorithms/all_free_variable_candidates_heuristic.hpp index ad21bffb..1b277d0e 100644 --- a/include/algorithms/random_walk_variable_candidates_heuristic.hpp +++ b/include/algorithms/all_free_variable_candidates_heuristic.hpp @@ -37,10 +37,10 @@ namespace ghost { namespace algorithms { - class RandomWalkVariableCandidatesHeuristic : public VariableCandidatesHeuristic + class AllFreeVariableCandidatesHeuristic : public VariableCandidatesHeuristic { public: - RandomWalkVariableCandidatesHeuristic(); + AllFreeVariableCandidatesHeuristic(); std::vector compute_variable_candidates( const SearchUnitData& data ) const override; }; diff --git a/include/algorithms/random_walk_variable_heuristic.hpp b/include/algorithms/uniform_variable_heuristic.hpp similarity index 94% rename from include/algorithms/random_walk_variable_heuristic.hpp rename to include/algorithms/uniform_variable_heuristic.hpp index f1a23ae0..5d6be983 100644 --- a/include/algorithms/random_walk_variable_heuristic.hpp +++ b/include/algorithms/uniform_variable_heuristic.hpp @@ -37,10 +37,10 @@ namespace ghost { namespace algorithms { - class RandomWalkVariableHeuristic : public VariableHeuristic + class UniformVariableHeuristic : public VariableHeuristic { public: - RandomWalkVariableHeuristic(); + UniformVariableHeuristic(); int select_variable( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const override; }; diff --git a/include/macros.hpp b/include/macros.hpp index c819b532..9f88e27b 100644 --- a/include/macros.hpp +++ b/include/macros.hpp @@ -41,3 +41,7 @@ #if defined GHOST_RANDOM_WALK #define GHOST_TRACE #endif + +#if defined GHOST_HILL_CLIMBING +#define GHOST_TRACE +#endif diff --git a/include/search_unit.hpp b/include/search_unit.hpp index b8ceb39b..d806cad3 100644 --- a/include/search_unit.hpp +++ b/include/search_unit.hpp @@ -56,7 +56,7 @@ #include "algorithms/value_heuristic.hpp" #include "algorithms/error_projection_algorithm.hpp" -#include "algorithms/adaptive_search_variable_heuristic.hpp" +#include "algorithms/uniform_variable_heuristic.hpp" #include "algorithms/adaptive_search_variable_candidates_heuristic.hpp" #include "algorithms/adaptive_search_value_heuristic.hpp" #include "algorithms/adaptive_search_error_projection_algorithm.hpp" @@ -67,13 +67,15 @@ #include "algorithms/culprit_search_error_projection_algorithm.hpp" -#if defined GHOST_RANDOM_WALK -#include "algorithms/random_walk_variable_heuristic.hpp" -#include "algorithms/random_walk_variable_candidates_heuristic.hpp" -#include "algorithms/random_walk_value_heuristic.hpp" +#if defined GHOST_RANDOM_WALK || defined GHOST_HILL_CLIMBING +#include "algorithms/all_free_variable_candidates_heuristic.hpp" #include "algorithms/null_error_projection_algorithm.hpp" #endif +#if defined GHOST_RANDOM_WALK +#include "algorithms/random_walk_value_heuristic.hpp" +#endif + #include "macros.hpp" namespace ghost @@ -499,10 +501,12 @@ namespace ghost // Otherwise try them first.) void local_minimum_management( int variable_to_change, int new_value, bool no_other_variables_to_try ) { + must_compute_variable_candidates = false; + if( no_other_variables_to_try ) // || rng.uniform(1, 100) <= 10 //10% chance to force tabu-marking even if there are other variables to explore. { data.tabu_list[ variable_to_change ] = options.tabu_time_local_min + data.local_moves; - must_compute_variable_candidates = true; + // must_compute_variable_candidates = true; ++data.local_minimum; } else @@ -510,7 +514,7 @@ namespace ghost #if defined GHOST_TRACE COUT << "Try other variables: not a local minimum yet.\n"; #endif - must_compute_variable_candidates = false; + // must_compute_variable_candidates = false; } } @@ -581,7 +585,7 @@ namespace ghost SearchUnit( Model&& moved_model, const Options& options ) : SearchUnit( std::move( moved_model ), options, - std::make_unique(), + std::make_unique(), std::make_unique(), std::make_unique(), std::make_unique() ) @@ -674,8 +678,6 @@ namespace ghost COUT << "Projected error of var[" << i << "]: " << data.error_variables[i] << "\n"; #endif - - // TODO: to replace after a potential reset() call (l700), to save some computations? // Estimate which variables need to be changed if( must_compute_variable_candidates ) variable_candidates = variable_candidates_heuristic->compute_variable_candidates( data ); @@ -702,7 +704,7 @@ namespace ghost } #if defined GHOST_TRACE - if( variable_heuristic->get_name().compare( "Adaptive Search" ) == 0 ) + if( variable_candidates_heuristic->get_name().compare( "Adaptive Search" ) == 0 ) { COUT << "\n(Adaptive Search Variable Candidates Heuristic) Variable candidates: v[" << static_cast( variable_candidates[0] ) << "]=" << model.variables[ static_cast( variable_candidates[0] ) ].get_value(); for( int i = 1 ; i < static_cast( variable_candidates.size() ) ; ++i ) @@ -710,20 +712,28 @@ namespace ghost COUT << "\n"; } else - if( variable_heuristic->get_name().compare( "Antidote Search" ) == 0 ) + if( variable_candidates_heuristic->get_name().compare( "All Free" ) == 0 ) { - auto distrib = std::discrete_distribution( data.error_variables.begin(), data.error_variables.end() ); - std::vector vec( data.number_variables, 0 ); - for( int n = 0 ; n < 10000 ; ++n ) - ++vec[ rng.variate( distrib ) ]; - std::vector> vec_pair( data.number_variables ); - for( int n = 0 ; n < data.number_variables ; ++n ) - vec_pair[n] = std::make_pair( n, vec[n] ); - std::sort( vec_pair.begin(), vec_pair.end(), [&](std::pair &a, std::pair &b){ return a.second > b.second; } ); - COUT << "\n(Antidote Search Variable Candidates Heuristic) Variable errors (normalized):\n"; - for( auto &v : vec_pair ) - COUT << "v[" << v.first << "]: " << std::fixed << std::setprecision(3) << static_cast( v.second ) / 10000 << "\n"; + COUT << "\n(All Free Variable Candidates Heuristic) Variable candidates: v[" << static_cast( variable_candidates[0] ) << "]=" << model.variables[ static_cast( variable_candidates[0] ) ].get_value(); + for( int i = 1 ; i < static_cast( variable_candidates.size() ) ; ++i ) + COUT << ", v[" << static_cast( variable_candidates[i] ) << "]=" << model.variables[ static_cast( variable_candidates[i] ) ].get_value(); + COUT << "\n"; } + else + if( variable_candidates_heuristic->get_name().compare( "Antidote Search" ) == 0 ) + { + auto distrib = std::discrete_distribution( data.error_variables.begin(), data.error_variables.end() ); + std::vector vec( data.number_variables, 0 ); + for( int n = 0 ; n < 10000 ; ++n ) + ++vec[ rng.variate( distrib ) ]; + std::vector> vec_pair( data.number_variables ); + for( int n = 0 ; n < data.number_variables ; ++n ) + vec_pair[n] = std::make_pair( n, vec[n] ); + std::sort( vec_pair.begin(), vec_pair.end(), [&](std::pair &a, std::pair &b){ return a.second > b.second; } ); + COUT << "\n(Antidote Search Variable Candidates Heuristic) Variable errors (normalized):\n"; + for( auto &v : vec_pair ) + COUT << "v[" << v.first << "]: " << std::fixed << std::setprecision(3) << static_cast( v.second ) / 10000 << "\n"; + } #endif variable_to_change = variable_heuristic->select_variable( variable_candidates, data, rng ); diff --git a/include/solver.hpp b/include/solver.hpp index 65c360d2..cfb79d9e 100644 --- a/include/solver.hpp +++ b/include/solver.hpp @@ -57,7 +57,7 @@ #include "algorithms/value_heuristic.hpp" #include "algorithms/error_projection_algorithm.hpp" -#include "algorithms/adaptive_search_variable_heuristic.hpp" +#include "algorithms/uniform_variable_heuristic.hpp" #include "algorithms/adaptive_search_variable_candidates_heuristic.hpp" #include "algorithms/adaptive_search_value_heuristic.hpp" #include "algorithms/adaptive_search_error_projection_algorithm.hpp" @@ -68,13 +68,15 @@ #include "algorithms/culprit_search_error_projection_algorithm.hpp" -#if defined GHOST_RANDOM_WALK -#include "algorithms/random_walk_variable_heuristic.hpp" -#include "algorithms/random_walk_variable_candidates_heuristic.hpp" -#include "algorithms/random_walk_value_heuristic.hpp" +#if defined GHOST_RANDOM_WALK || defined GHOST_HILL_CLIMBING +#include "algorithms/all_free_variable_candidates_heuristic.hpp" #include "algorithms/null_error_projection_algorithm.hpp" #endif +#if defined GHOST_RANDOM_WALK +#include "algorithms/random_walk_value_heuristic.hpp" +#endif + #include "macros.hpp" namespace ghost @@ -470,13 +472,13 @@ namespace ghost if( _options.number_start_samplings < 0 ) _options.number_start_samplings = 10; -#if defined GHOST_RANDOM_WALK +#if defined GHOST_RANDOM_WALK || defined GHOST_HILL_CLIMBING _options.percent_chance_escape_plateau = 0; + _options.number_start_samplings = 1; _options.tabu_time_local_min = 0; _options.tabu_time_selected = 0; - _options.number_start_samplings = 1; #endif - + double chrono_search; double chrono_full_computation; @@ -500,10 +502,17 @@ namespace ghost #if defined GHOST_RANDOM_WALK SearchUnit search_unit( _model_builder.build_model(), _options, - std::make_unique(), - std::make_unique(), + std::make_unique(), + std::make_unique(), std::make_unique(), std::make_unique() ); +#elif defined GHOST_HILL_CLIMBING + SearchUnit search_unit( _model_builder.build_model(), + _options, + std::make_unique(), + std::make_unique(), + std::make_unique(), + std::make_unique() ); #else SearchUnit search_unit( _model_builder.build_model(), _options ); @@ -546,10 +555,17 @@ namespace ghost #if defined GHOST_RANDOM_WALK units.emplace_back( _model_builder.build_model(), _options, - std::make_unique(), - std::make_unique(), + std::make_unique(), + std::make_unique(), std::make_unique(), std::make_unique() ); +#elif defined GHOST_HILL_CLIMBING + units.emplace_back( _model_builder.build_model(), + _options, + std::make_unique(), + std::make_unique(), + std::make_unique(), + std::make_unique() ); #else units.emplace_back( _model_builder.build_model(), _options ); diff --git a/src/algorithms/adaptive_search_variable_heuristic.cpp b/src/algorithms/adaptive_search_variable_heuristic.cpp deleted file mode 100644 index 54eb8a88..00000000 --- a/src/algorithms/adaptive_search_variable_heuristic.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * GHOST (General meta-Heuristic Optimization Solving Tool) is a C++ framework - * designed to help developers to model and implement optimization problem - * solving. It contains a meta-heuristic solver aiming to solve any kind of - * combinatorial and optimization real-time problems represented by a CSP/COP/EF-CSP/EF-COP. - * - * First developed to solve game-related optimization problems, GHOST can be used for - * any kind of applications where solving combinatorial and optimization problems. In - * particular, it had been designed to be able to solve not-too-complex problem instances - * within some milliseconds, making it very suitable for highly reactive or embedded systems. - * Please visit https://github.com/richoux/GHOST for further information. - * - * Copyright (C) 2014-2024 Florian Richoux - * - * This file is part of GHOST. - * GHOST is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * GHOST is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with GHOST. If not, see http://www.gnu.org/licenses/. - */ - -#include "algorithms/adaptive_search_variable_heuristic.hpp" - -using ghost::algorithms::AdaptiveSearchVariableHeuristic; - -AdaptiveSearchVariableHeuristic::AdaptiveSearchVariableHeuristic() - : VariableHeuristic( "Adaptive Search" ) -{ } - -int AdaptiveSearchVariableHeuristic::select_variable( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const -{ - return static_cast( rng.pick( candidates ) ); -} diff --git a/src/algorithms/random_walk_variable_candidates_heuristic.cpp b/src/algorithms/all_free_variable_candidates_heuristic.cpp similarity index 70% rename from src/algorithms/random_walk_variable_candidates_heuristic.cpp rename to src/algorithms/all_free_variable_candidates_heuristic.cpp index 1d9432a3..53a1a917 100644 --- a/src/algorithms/random_walk_variable_candidates_heuristic.cpp +++ b/src/algorithms/all_free_variable_candidates_heuristic.cpp @@ -27,17 +27,20 @@ * along with GHOST. If not, see http://www.gnu.org/licenses/. */ -#include "algorithms/random_walk_variable_candidates_heuristic.hpp" +#include "algorithms/all_free_variable_candidates_heuristic.hpp" -using ghost::algorithms::RandomWalkVariableCandidatesHeuristic; +using ghost::algorithms::AllFreeVariableCandidatesHeuristic; -RandomWalkVariableCandidatesHeuristic::RandomWalkVariableCandidatesHeuristic() - : VariableCandidatesHeuristic( "Random Walk" ) +AllFreeVariableCandidatesHeuristic::AllFreeVariableCandidatesHeuristic() + : VariableCandidatesHeuristic( "All Free" ) { } -std::vector RandomWalkVariableCandidatesHeuristic::compute_variable_candidates( const SearchUnitData& data ) const +std::vector AllFreeVariableCandidatesHeuristic::compute_variable_candidates( const SearchUnitData& data ) const { - std::vector full_variables_list(data.number_variables); - std::iota( full_variables_list.begin(), full_variables_list.end(), 0.0 ); - return full_variables_list; + std::vector free_variables_list; + for( int variable_id = 0 ; variable_id < data.number_variables ; ++variable_id ) + if( data.tabu_list[ variable_id ] <= data.local_moves ) + free_variables_list.push_back( variable_id ); + + return free_variables_list; } diff --git a/src/algorithms/random_walk_variable_heuristic.cpp b/src/algorithms/uniform_variable_heuristic.cpp similarity index 80% rename from src/algorithms/random_walk_variable_heuristic.cpp rename to src/algorithms/uniform_variable_heuristic.cpp index 92467c9f..5d959d5d 100644 --- a/src/algorithms/random_walk_variable_heuristic.cpp +++ b/src/algorithms/uniform_variable_heuristic.cpp @@ -27,15 +27,15 @@ * along with GHOST. If not, see http://www.gnu.org/licenses/. */ -#include "algorithms/random_walk_variable_heuristic.hpp" +#include "algorithms/uniform_variable_heuristic.hpp" -using ghost::algorithms::RandomWalkVariableHeuristic; +using ghost::algorithms::UniformVariableHeuristic; -RandomWalkVariableHeuristic::RandomWalkVariableHeuristic() - : VariableHeuristic( "Random Walk" ) +UniformVariableHeuristic::UniformVariableHeuristic() + : VariableHeuristic( "Uniform" ) { } -int RandomWalkVariableHeuristic::select_variable( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const +int UniformVariableHeuristic::select_variable( const std::vector& candidates, const SearchUnitData& data, randutils::mt19937_rng& rng ) const { return static_cast( rng.pick( candidates ) ); }