From 4e1fc3db2100828c5ae463a1a30ef47bb5d88df6 Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Fri, 22 Mar 2024 18:25:05 -0500 Subject: [PATCH] WIP: refactoring evaluations. --- include/cconfigspace.h | 1 + include/cconfigspace/base.h | 4 + include/cconfigspace/evaluation.h | 163 +---------------- include/cconfigspace/evaluation_binding.h | 177 +++++++++++++++++++ include/cconfigspace/features_evaluation.h | 142 +-------------- include/cconfigspace/objective_space.h | 12 +- include/cconfigspace/tree_evaluation.h | 144 +-------------- src/Makefile.am | 2 + src/cconfigspace_internal.h | 2 +- src/evaluation.c | 176 ++----------------- src/evaluation_binding.c | 121 +++++++++++++ src/evaluation_binding_internal.h | 92 ++++++++++ src/evaluation_internal.h | 5 + src/features_evaluation.c | 194 +++------------------ src/features_evaluation_internal.h | 5 + src/features_tuner_random.c | 9 +- src/objective_space.c | 16 +- src/tree_evaluation.c | 179 ++----------------- src/tree_evaluation_internal.h | 5 + src/tree_tuner_random.c | 9 +- src/tuner_random.c | 8 +- tests/test_random_features_tuner.c | 14 +- tests/test_random_tree_tuner.c | 7 +- tests/test_random_tuner.c | 6 +- 24 files changed, 523 insertions(+), 970 deletions(-) create mode 100644 include/cconfigspace/evaluation_binding.h create mode 100644 src/evaluation_binding.c create mode 100644 src/evaluation_binding_internal.h diff --git a/include/cconfigspace.h b/include/cconfigspace.h index 3c6be6ef..e08a50ed 100644 --- a/include/cconfigspace.h +++ b/include/cconfigspace.h @@ -20,6 +20,7 @@ #include "cconfigspace/features.h" #include "cconfigspace/objective_space.h" #include "cconfigspace/evaluation.h" +#include "cconfigspace/evaluation_binding.h" #include "cconfigspace/features_evaluation.h" #include "cconfigspace/tuner.h" #include "cconfigspace/features_tuner.h" diff --git a/include/cconfigspace/base.h b/include/cconfigspace/base.h index 8e336e2d..f3e05606 100644 --- a/include/cconfigspace/base.h +++ b/include/cconfigspace/base.h @@ -129,6 +129,10 @@ typedef struct _ccs_features_s *ccs_features_t; * An opaque type defining a CCS objective space. */ typedef struct _ccs_objective_space_s *ccs_objective_space_t; +/** + * An opaque type defining a CCS evaluation binding. + */ +typedef struct _ccs_evaluation_binding_s *ccs_evaluation_binding_t; /** * An opaque type defining a CCS evaluation. */ diff --git a/include/cconfigspace/evaluation.h b/include/cconfigspace/evaluation.h index 1380168a..b6f7712d 100644 --- a/include/cconfigspace/evaluation.h +++ b/include/cconfigspace/evaluation.h @@ -6,36 +6,11 @@ extern "C" { #endif /** - * @file evaluation.h An evaluation is a binding (see binding.h) over an - * objective space (see objective_space.h) given a specific configuration (see - * configuration.h). Successful evaluations over the same objective space are - * weakly ordered by their objective values. Evaluation that have failed must - * report a result code different than CCS_RESULT_SUCCESS. + * @file evaluation.h An evaluation is an evaluation binding + * (see evaluation_binding.h) given a specific configuration + * (see configuration.h). */ -/** - * The different possible return codes when comparing two evaluations. - */ -enum ccs_comparison_e { - /** The first configuration is better then the second */ - CCS_COMPARISON_BETTER = -1, - /** The two configurations are equivalent */ - CCS_COMPARISON_EQUIVALENT = 0, - /** The first configuration is worse than the second */ - CCS_COMPARISON_WORSE = 1, - /** The two configurations cannot be compared */ - CCS_COMPARISON_NOT_COMPARABLE = 2, - /** Guard */ - CCS_COMPARISON_MAX, - /** Try forcing 32 bits value for bindings */ - CCS_COMPARISON_FORCE_32BIT = INT32_MAX -}; - -/** - * A commodity type to represent CCS the result of comparing evaluations. - */ -typedef enum ccs_comparison_e ccs_comparison_t; - /** * Create a new instance of an evaluation on a given objective_space for a given * configuration. @@ -69,23 +44,6 @@ ccs_create_evaluation( ccs_datum_t *values, ccs_evaluation_t *evaluation_ret); -/** - * Get the objective space associated with an evaluation. - * @param[in] evaluation - * @param[out] objective_space_ret a pointer to the variable that will - * contain the objective space - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p objective_space_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_evaluation_get_objective_space( - ccs_evaluation_t evaluation, - ccs_objective_space_t *objective_space_ret); - /** * Get the configuration associated with an evaluation. * @param[in] evaluation @@ -103,121 +61,6 @@ ccs_evaluation_get_configuration( ccs_evaluation_t evaluation, ccs_configuration_t *configuration_ret); -/** - * Get the result code associated with an evaluation. - * @param[in] evaluation - * @param[out] result_ret a pointer to the variable that will contain the - * returned result code - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p result_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_evaluation_get_result( - ccs_evaluation_t evaluation, - ccs_evaluation_result_t *result_ret); - -/** - * Check that an evaluation values are valid in the objective space. - * @param[in] evaluation - * @param[out] is_valid_ret a pointer to a variable that will hold the result - * of the check. Result will be #CCS_TRUE if the - * evaluation is valid. Result will be #CCS_FALSE if - * an parameter value is not a valid value - * for this parameter - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * evaluation - * @return #CCS_RESULT_ERROR_INVALID_EVALUATION if \p evaluation was found to be - * invalid in the context of the objective space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_evaluation_check(ccs_evaluation_t evaluation, ccs_bool_t *is_valid_ret); - -/** - * Get the value of an objective for a valid evaluation in the context of its - * objective space. - * @param[in] evaluation - * @param[in] index the index of the objective in the objective space - * @param[out] value_ret a pointer to the variable that will contain the value - * of the objective - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL; or if there - * was an issue evaluating the objective - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the - * number of objective in the objective space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_evaluation_get_objective_value( - ccs_evaluation_t evaluation, - size_t index, - ccs_datum_t *value_ret); - -/** - * Get the values of the objectives for a valid evaluation in the context of its - * objective space. - * @param[in] evaluation - * @param[in] num_values the number of values that \p values can contain - * @param[out] values an optional array of values that will contain the returned - * objective values. If values is bigger than the number of - * objectives, extra values will be set to - * #CCS_DATA_TYPE_NONE - * @param[out] num_values_ret an optional pointer to a variable that will - * contain the number of values that are or would be - * returned. Can be NULL - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p values is NULL and \p - * num_values is greater than 0; or if values is NULL and num_values_ret is - * NULL; or if there was an issue evaluating any of the objectives - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_evaluation_get_objective_values( - ccs_evaluation_t evaluation, - size_t num_values, - ccs_datum_t *values, - size_t *num_values_ret); - -/** - * Compare two successful evaluations objectives. - * @param[in] evaluation the first evaluation - * @param[in] other_evaluation the second evaluation - * @param[out] result_ret a pointer to the variable that will contain the result - * of the comparison. Will contain - * #CCS_COMPARISON_BETTER, #CCS_COMPARISON_EQUIVALENT, - * #CCS_COMPARISON_WORSE, or - * #CCS_COMPARISON_NOT_COMPARABLE if the first - * evaluation is found to be respectively better, - * equivalent, worse, or not comparable with the second - * evaluation. - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation or \p - * other_evaluation are not valid CCS evaluations; or if \p evaluation and \p - * other_evaluation do not share the same objective space; or if any of the - * configuration is associated a result code different than CCS_SUCESS - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p result_ret is NULL; or if there - * was an issue evaluating any of the objectives - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_evaluation_compare( - ccs_evaluation_t evaluation, - ccs_evaluation_t other_evaluation, - ccs_comparison_t *result_ret); - #ifdef __cplusplus } #endif diff --git a/include/cconfigspace/evaluation_binding.h b/include/cconfigspace/evaluation_binding.h new file mode 100644 index 00000000..81555c9f --- /dev/null +++ b/include/cconfigspace/evaluation_binding.h @@ -0,0 +1,177 @@ +#ifndef _CCS_EVALUATION_BINDING_H +#define _CCS_EVALUATION_BINDING_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file evaluation_binding.h An evaluation binding is a binding (see + * binding.h) over an objective space (see objective_space.h). Successful + * evaluations over the same objective space are weakly ordered by their + * objective values. Evaluation that have failed must report a result code + * different than CCS_RESULT_SUCCESS. + */ + +/** + * The different possible return codes when comparing two evaluations. + */ +enum ccs_comparison_e { + /** The first configuration is better then the second */ + CCS_COMPARISON_BETTER = -1, + /** The two configurations are equivalent */ + CCS_COMPARISON_EQUIVALENT = 0, + /** The first configuration is worse than the second */ + CCS_COMPARISON_WORSE = 1, + /** The two configurations cannot be compared */ + CCS_COMPARISON_NOT_COMPARABLE = 2, + /** Guard */ + CCS_COMPARISON_MAX, + /** Try forcing 32 bits value for bindings */ + CCS_COMPARISON_FORCE_32BIT = INT32_MAX +}; + +/** + * A commodity type to represent CCS the result of comparing evaluations. + */ +typedef enum ccs_comparison_e ccs_comparison_t; + +/** + * Get the objective space associated with an evaluation binding. + * @param[in] evaluation_binding + * @param[out] objective_space_ret a pointer to the variable that will + * contain the objective space + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation_binding is not a + * valid CCS evaluation binding + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p objective_space_ret is NULL + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_evaluation_binding_get_objective_space( + ccs_evaluation_binding_t evaluation, + ccs_objective_space_t *objective_space_ret); + +/** + * Get the result code associated with an evaluation. + * @param[in] evaluation + * @param[out] result_ret a pointer to the variable that will contain the + * returned result code + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS + * evaluation + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p result_ret is NULL + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_evaluation_binding_get_result( + ccs_evaluation_binding_t evaluation, + ccs_evaluation_result_t *result_ret); + +/** + * Get the value of an objective for a valid evaluation in the context of its + * objective space. + * @param[in] evaluation + * @param[in] index the index of the objective in the objective space + * @param[out] value_ret a pointer to the variable that will contain the value + * of the objective + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS + * evaluation + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL; or if there + * was an issue evaluating the objective + * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the + * number of objective in the objective space + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_evaluation_binding_get_objective_value( + ccs_evaluation_binding_t evaluation, + size_t index, + ccs_datum_t *value_ret); + +/** + * Get the values of the objectives for a valid evaluation in the context of its + * objective space. + * @param[in] evaluation + * @param[in] num_values the number of values that \p values can contain + * @param[out] values an optional array of values that will contain the returned + * objective values. If values is bigger than the number of + * objectives, extra values will be set to + * #CCS_DATA_TYPE_NONE + * @param[out] num_values_ret an optional pointer to a variable that will + * contain the number of values that are or would be + * returned. Can be NULL + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS + * evaluation binding + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p values is NULL and \p + * num_values is greater than 0; or if values is NULL and num_values_ret is + * NULL; or if there was an issue evaluating any of the objectives + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_evaluation_binding_get_objective_values( + ccs_evaluation_binding_t evaluation, + size_t num_values, + ccs_datum_t *values, + size_t *num_values_ret); + +/** + * Check that an evaluation values are valid in the objective space. + * @param[in] evaluation + * @param[out] is_valid_ret a pointer to a variable that will hold the result + * of the check. Result will be #CCS_TRUE if the + * evaluation is valid. Result will be #CCS_FALSE if + * an parameter value is not a valid value + * for this parameter + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS + * evaluation + * @return #CCS_RESULT_ERROR_INVALID_EVALUATION if \p evaluation was found to be + * invalid in the context of the objective space + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_evaluation_binding_check( + ccs_evaluation_binding_t evaluation, + ccs_bool_t *is_valid_ret); + +/** + * Compare two successful evaluations objectives. + * @param[in] evaluation the first evaluation + * @param[in] other_evaluation the second evaluation + * @param[out] result_ret a pointer to the variable that will contain the result + * of the comparison. Will contain + * #CCS_COMPARISON_BETTER, #CCS_COMPARISON_EQUIVALENT, + * #CCS_COMPARISON_WORSE, or + * #CCS_COMPARISON_NOT_COMPARABLE if the first + * evaluation is found to be respectively better, + * equivalent, worse, or not comparable with the second + * evaluation. + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation or \p + * other_evaluation are not valid CCS evaluations; or if \p evaluation and \p + * other_evaluation do not share the same objective space; or if any of the + * the evaluation is associated a result code different than #CCS_RESULT_SUCESS; or if both evaluations are not ot the same type + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p result_ret is NULL; or if there + * was an issue evaluating any of the objectives + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_evaluation_binding_compare( + ccs_evaluation_binding_t evaluation, + ccs_evaluation_binding_t other_evaluation, + ccs_comparison_t *result_ret); + +#ifdef __cplusplus +} +#endif + +#endif //_CCS_EVALUATION_BINDING_H diff --git a/include/cconfigspace/features_evaluation.h b/include/cconfigspace/features_evaluation.h index 5f4805ca..07b96810 100644 --- a/include/cconfigspace/features_evaluation.h +++ b/include/cconfigspace/features_evaluation.h @@ -7,11 +7,8 @@ extern "C" { /** * @file features_evaluation.h - * A features evaluation is a binding (see binding.h) over an objective space - * given a specific configuration (see configuration.h) and features (see - * features.h). Successful evaluations over the same objective space are weakly - * ordered by their objective values. Evaluation that have failed must report a - * result code different than CCS_RESULT_SUCCESS. + * A features evaluation is an evaluation binding (see evaluation_binding.h) + * configuration (see configuration.h) and features (see features.h). */ /** @@ -50,23 +47,6 @@ ccs_create_features_evaluation( ccs_datum_t *values, ccs_features_evaluation_t *features_evaluation_ret); -/** - * Get the objective space associated with a features evaluation. - * @param[in] features_evaluation - * @param[out] objective_space_ret a pointer to the variable that will - * contain the objective space - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_evaluation is not a - * valid CCS features_evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p objective_space_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_evaluation_get_objective_space( - ccs_features_evaluation_t features_evaluation, - ccs_objective_space_t *objective_space_ret); - /** * Get the configuration associated with a features evaluation. * @param[in] features_evaluation @@ -101,124 +81,6 @@ ccs_features_evaluation_get_features( ccs_features_evaluation_t features_evaluation, ccs_features_t *features_ret); -/** - * Get the result code associated with a features evaluation. - * @param[in] features_evaluation - * @param[out] result_ret a pointer to the variable that will contain the - * returned result code - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_evaluation is not a - * valid CCS features evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p result_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_evaluation_get_result( - ccs_features_evaluation_t features_evaluation, - ccs_evaluation_result_t *result_ret); - -/** - * Get the value of an objective for a valid features evaluation in the context - * of its objective space. - * @param[in] features_evaluation - * @param[in] index the index of the objective in the objective space - * @param[out] value_ret a pointer to the variable that will contain the value - * of the objective - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_evaluation is not a - * valid CCS features evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL; or if there - * was an issue evaluating the objective - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the - * number of objective in the objective space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_evaluation_get_objective_value( - ccs_features_evaluation_t features_evaluation, - size_t index, - ccs_datum_t *value_ret); - -/** - * Get the values of the objectives for a valid features evaluation in the - * context of its objective space. - * @param[in] features_evaluation - * @param[in] num_values the number of values that \p values can contain - * @param[out] values an optional array of values that will contain the returned - * objective values. If values is bigger than the number of - * objectives, extra values will be set to - * #CCS_DATA_TYPE_NONE - * @param[out] num_values_ret an optional pointer to a variable that will - * contain the number of values that are or would be - * returned. Can be NULL - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_evaluation is not a - * valid CCS features evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p values is NULL and \p - * num_values is greater than 0; or if values is NULL and num_values_ret is - * NULL; or if there was an issue evaluating any of the objectives - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_evaluation_get_objective_values( - ccs_features_evaluation_t features_evaluation, - size_t num_values, - ccs_datum_t *values, - size_t *num_values_ret); - -/** - * Compare two successful features evaluations objectives. - * @param[in] features_evaluation the first features evaluation - * @param[in] other_features_evaluation the second features evaluation - * @param[out] result_ret a pointer to the variable that will contain the result - * of the comparison. Will contain - * #CCS_COMPARISON_BETTER, #CCS_COMPARISON_EQUIVALENT, - * #CCS_COMPARISON_WORSE, or - * #CCS_COMPARISON_NOT_COMPARABLE if the first features - * evaluation is found to be respectively better, - * equivalent, worse, or not comparable with the second - * features evaluation. - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_evaluation or \p - * other_features_evaluation are not valid CCS features evaluations; or if \p - * features_evaluation and \p other_features_evaluation do not share the same - * objective space; or if any of the configuration is associated a result code - * different than CCS_SUCESS - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p result_ret is NULL; or if there - * was an issue evaluating any of the objectives - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_evaluation_compare( - ccs_features_evaluation_t features_evaluation, - ccs_features_evaluation_t other_features_evaluation, - ccs_comparison_t *result_ret); - -/** - * Check that a features evaluation values are valid in the objective space. - * @param[in] features_evaluation - * @param[out] is_valid_ret a pointer to a variable that will hold the result - * of the check. Result will be #CCS_TRUE if the - * features_evaluation is valid. Result will be - * #CCS_FALSE if an parameter value is not a valid - * value for this parameter - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_evaluation is not a - * valid CCS features evaluation - * @return #CCS_RESULT_ERROR_INVALID_EVALUATION if \p features_evaluation was - * found to be invalid in the context of the objective space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_evaluation_check( - ccs_features_evaluation_t features_evaluation, - ccs_bool_t *is_valid_ret); - #ifdef __cplusplus } #endif diff --git a/include/cconfigspace/objective_space.h b/include/cconfigspace/objective_space.h index 1c12ffe4..78067d89 100644 --- a/include/cconfigspace/objective_space.h +++ b/include/cconfigspace/objective_space.h @@ -83,18 +83,18 @@ ccs_create_objective_space( * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not a * valid CCS objective space; or if \p evaluation is not a valid CCS - * evaluation + * evaluation binding * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p is_valid_ret is NULL - * @return #CCS_RESULT_ERROR_INVALID_EVALUATION if \p evaluation is not - * associated to the objective space + * @return #CCS_RESULT_ERROR_INVALID_EVALUATION_BINDING if \p evaluation + * is not associated to the objective space * @remarks * This function is thread-safe */ extern ccs_result_t ccs_objective_space_check_evaluation( - ccs_objective_space_t objective_space, - ccs_evaluation_t evaluation, - ccs_bool_t *is_valid_ret); + ccs_objective_space_t objective_space, + ccs_evaluation_binding_t evaluation, + ccs_bool_t *is_valid_ret); /** * Get the objective of rank index in a objective space. diff --git a/include/cconfigspace/tree_evaluation.h b/include/cconfigspace/tree_evaluation.h index 4f8df716..cc865005 100644 --- a/include/cconfigspace/tree_evaluation.h +++ b/include/cconfigspace/tree_evaluation.h @@ -5,12 +5,10 @@ extern "C" { #endif -/** @file tree_evaluation.h A tree evaluation is a binding (see binding.h) over - * an objective space (see objective_space.h) given a specific tree - * configuration (see tree_configuration.h). Successful evaluations over the - * same objective space are weakly ordered by their objective values. - * Evaluation that have failed must report a result code different than - * CCS_RESULT_SUCCESS. +/** + * @file tree_evaluation.h A tree evaluation is an evaluation binding + * (see evaluation_binding.h) given a specific tree configuration + * (see tree_configuration.h). */ /** @@ -47,23 +45,6 @@ ccs_create_tree_evaluation( ccs_datum_t *values, ccs_tree_evaluation_t *evaluation_ret); -/** - * Get the objective space associated with a tree evaluation. - * @param[in] evaluation - * @param[out] objective_space_ret a pointer to the variable that will - * contain the objective space - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * tree evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p objective_space_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_tree_evaluation_get_objective_space( - ccs_tree_evaluation_t evaluation, - ccs_objective_space_t *objective_space_ret); - /** * Get the configuration associated with a tree evaluation. * @param[in] evaluation @@ -81,123 +62,6 @@ ccs_tree_evaluation_get_configuration( ccs_tree_evaluation_t evaluation, ccs_tree_configuration_t *configuration_ret); -/** - * Get the result code associated with a tree evaluation. - * @param[in] evaluation - * @param[out] result_ret a pointer to the variable that will contain the - * returned error code - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * tree evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p result_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_tree_evaluation_get_result( - ccs_tree_evaluation_t evaluation, - ccs_evaluation_result_t *result_ret); - -/** - * Check that an evaluation values are valid in the objective space. - * @param[in] evaluation - * @param[out] is_valid_ret a pointer to a variable that will hold the result - * of the check. Result will be #CCS_TRUE if the - * evaluation is valid. Result will be #CCS_FALSE if - * an parameter value is not a valid value - * for this parameter - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * tree evaluation - * @return #CCS_RESULT_ERROR_INVALID_EVALUATION if \p evaluation was found to be - * invalid in the context of the objective space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_tree_evaluation_check( - ccs_tree_evaluation_t evaluation, - ccs_bool_t *is_valid_ret); - -/** - * Get the value of an objective for a valid tree evaluation in the context of - * its objective space. - * @param[in] evaluation - * @param[in] index the index of the objective in the objective space - * @param[out] value_ret a pointer to the variable that will contain the value - * of the objective - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * tree evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL; or if there - * was an issue evaluating the objective - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the - * number of objective in the objective space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_tree_evaluation_get_objective_value( - ccs_tree_evaluation_t evaluation, - size_t index, - ccs_datum_t *value_ret); - -/** - * Get the values of the objectives for a valid tree evaluation in the context - * of its objective space. - * @param[in] evaluation - * @param[in] num_values the number of values that \p values can contain - * @param[out] values an optional array of values that will contain the returned - * objective values. If values is bigger than the number of - * objectives, extra values will be set to - * #CCS_DATA_TYPE_NONE - * @param[out] num_values_ret an optional pointer to a variable that will - * contain the number of values that are or would be - * returned. Can be NULL - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * tree evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p values is NULL and \p - * num_values is greater than 0; or if values is NULL and num_values_ret is - * NULL; or if there was an issue evaluating any of the objectives - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_tree_evaluation_get_objective_values( - ccs_tree_evaluation_t evaluation, - size_t num_values, - ccs_datum_t *values, - size_t *num_values_ret); - -/** - * Compare two successful tree evaluations objectives. - * @param[in] evaluation the first evaluation - * @param[in] other_evaluation the second evaluation - * @param[out] result_ret a pointer to the variable that will contain the result - * of the comparison. Will contain - * #CCS_COMPARISON_BETTER, #CCS_COMPARISON_EQUIVALENT, - * #CCS_COMPARISON_WORSE, or - * #CCS_COMPARISON_NOT_COMPARABLE if the first - * evaluation is found to be respectively better, - * equivalent, worse, or not comparable with the second - * evaluation. - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation or \p - * other_evaluation are not valid CCS tree evaluations; or if \p evaluation and - * \p other_evaluation do not share the same objective space; or if any of the - * configuration is associated a result code different than CCS_SUCESS - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p result_ret is NULL; or if there - * was an issue evaluating any of the objectives - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_tree_evaluation_compare( - ccs_tree_evaluation_t evaluation, - ccs_tree_evaluation_t other_evaluation, - ccs_comparison_t *result_ret); - #ifdef __cplusplus } #endif diff --git a/src/Makefile.am b/src/Makefile.am index 000f5e3b..9cd2b778 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -76,6 +76,8 @@ libcconfigspace_la_SOURCES = \ objective_space.c \ objective_space_internal.h \ objective_space_deserialize.h \ + evaluation_binding.c \ + evaluation_binding_internal.h \ evaluation.c \ evaluation_internal.h \ evaluation_deserialize.h \ diff --git a/src/cconfigspace_internal.h b/src/cconfigspace_internal.h index ebeac147..ace49e0d 100644 --- a/src/cconfigspace_internal.h +++ b/src/cconfigspace_internal.h @@ -247,7 +247,7 @@ _ccs_do_nothing(void) CCS_RESULT_ERROR_INVALID_OBJECT, \ "Invalid CCS context '%s' == %p supplied", #c, c) -#define CCS_CHECK_EVALUATION(e) \ +#define CCS_CHECK_EVALUATION_BINDING(e) \ CCS_REFUTE_MSG( \ !(e) || !((_ccs_object_template_t *)(e))->data || \ (((_ccs_object_template_t *)(e))->obj.type != \ diff --git a/src/evaluation.c b/src/evaluation.c index 6258c3d5..2e560a78 100644 --- a/src/evaluation.c +++ b/src/evaluation.c @@ -1,4 +1,5 @@ #include "cconfigspace_internal.h" +#include "evaluation_binding_internal.h" #include "evaluation_internal.h" #include "configuration_internal.h" #include "objective_space_internal.h" @@ -155,11 +156,25 @@ _ccs_evaluation_cmp( return CCS_RESULT_SUCCESS; } +static ccs_result_t +_ccs_evaluation_compare( + ccs_evaluation_t evaluation, + ccs_evaluation_t other, + ccs_comparison_t *result_ret) +{ + CCS_VALIDATE(_ccs_evaluation_binding_compare( + (ccs_evaluation_binding_t)evaluation, + (ccs_evaluation_binding_t)other, + result_ret)); + return CCS_RESULT_SUCCESS; +} + static _ccs_evaluation_ops_t _evaluation_ops = { {&_ccs_evaluation_del, &_ccs_evaluation_serialize_size, &_ccs_evaluation_serialize}, &_ccs_evaluation_hash, - &_ccs_evaluation_cmp}; + &_ccs_evaluation_cmp, + &_ccs_evaluation_compare}; ccs_result_t ccs_create_evaluation( @@ -225,18 +240,6 @@ ccs_create_evaluation( return err; } -ccs_result_t -ccs_evaluation_get_objective_space( - ccs_evaluation_t evaluation, - ccs_objective_space_t *objective_space_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); - CCS_VALIDATE(_ccs_binding_get_context( - (ccs_binding_t)evaluation, - (ccs_context_t *)objective_space_ret)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_evaluation_get_configuration( ccs_evaluation_t evaluation, @@ -247,150 +250,3 @@ ccs_evaluation_get_configuration( *configuration_ret = evaluation->data->configuration; return CCS_RESULT_SUCCESS; } - -ccs_result_t -ccs_evaluation_get_result( - ccs_evaluation_t evaluation, - ccs_evaluation_result_t *result_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); - CCS_CHECK_PTR(result_ret); - *result_ret = evaluation->data->result; - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_evaluation_check(ccs_evaluation_t evaluation, ccs_bool_t *is_valid_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); - CCS_VALIDATE(ccs_objective_space_check_evaluation( - evaluation->data->objective_space, evaluation, is_valid_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_evaluation_get_objective_value( - ccs_evaluation_t evaluation, - size_t index, - ccs_datum_t *value_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); - CCS_CHECK_PTR(value_ret); - ccs_expression_t expression; - ccs_objective_type_t type; - CCS_VALIDATE(ccs_objective_space_get_objective( - evaluation->data->objective_space, index, &expression, &type)); - CCS_VALIDATE(ccs_expression_eval( - expression, 1, (ccs_binding_t *)&evaluation, value_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_evaluation_get_objective_values( - ccs_evaluation_t evaluation, - size_t num_values, - ccs_datum_t *values, - size_t *num_values_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); - CCS_CHECK_ARY(num_values, values); - CCS_REFUTE(!values && !num_values_ret, CCS_RESULT_ERROR_INVALID_VALUE); - size_t count; - CCS_VALIDATE(ccs_objective_space_get_objectives( - evaluation->data->objective_space, 0, NULL, NULL, &count)); - if (values) { - CCS_REFUTE(count < num_values, CCS_RESULT_ERROR_INVALID_VALUE); - for (size_t i = 0; i < count; i++) { - ccs_expression_t expression; - ccs_objective_type_t type; - - CCS_VALIDATE(ccs_objective_space_get_objective( - evaluation->data->objective_space, i, - &expression, &type)); - CCS_VALIDATE(ccs_expression_eval( - expression, 1, (ccs_binding_t *)&evaluation, - values + i)); - } - for (size_t i = count; i < num_values; i++) - values[i] = ccs_none; - } - if (num_values_ret) - *num_values_ret = count; - return CCS_RESULT_SUCCESS; -} - -static inline int -_numeric_compare(const ccs_datum_t *a, const ccs_datum_t *b) -{ - if (a->type == CCS_DATA_TYPE_FLOAT) { - return a->value.f < b->value.f ? -1 : - a->value.f > b->value.f ? 1 : - 0; - } else { - return a->value.i < b->value.i ? -1 : - a->value.i > b->value.i ? 1 : - 0; - } -} - -// Could be using memoization here. -ccs_result_t -ccs_evaluation_compare( - ccs_evaluation_t evaluation, - ccs_evaluation_t other_evaluation, - ccs_comparison_t *result_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); - CCS_CHECK_OBJ(other_evaluation, CCS_OBJECT_TYPE_EVALUATION); - CCS_CHECK_PTR(result_ret); - if (evaluation == other_evaluation) { - *result_ret = CCS_COMPARISON_EQUIVALENT; - return CCS_RESULT_SUCCESS; - } - CCS_REFUTE( - evaluation->data->result || other_evaluation->data->result, - CCS_RESULT_ERROR_INVALID_OBJECT); - CCS_REFUTE( - evaluation->data->objective_space != - other_evaluation->data->objective_space, - CCS_RESULT_ERROR_INVALID_OBJECT); - size_t count; - CCS_VALIDATE(ccs_objective_space_get_objectives( - evaluation->data->objective_space, 0, NULL, NULL, &count)); - *result_ret = CCS_COMPARISON_EQUIVALENT; - for (size_t i = 0; i < count; i++) { - ccs_expression_t expression; - ccs_objective_type_t type; - ccs_datum_t values[2]; - int cmp; - - CCS_VALIDATE(ccs_objective_space_get_objective( - evaluation->data->objective_space, i, &expression, - &type)); - CCS_VALIDATE(ccs_expression_eval( - expression, 1, (ccs_binding_t *)&evaluation, values)); - CCS_VALIDATE(ccs_expression_eval( - expression, 1, (ccs_binding_t *)&other_evaluation, - values + 1)); - // Maybe relax to allow comparing Numerical values of different - // types. - if ((values[0].type != CCS_DATA_TYPE_INT && - values[0].type != CCS_DATA_TYPE_FLOAT) || - values[0].type != values[1].type) { - *result_ret = CCS_COMPARISON_NOT_COMPARABLE; - return CCS_RESULT_SUCCESS; - } - cmp = _numeric_compare(values, values + 1); - if (cmp) { - if (type == CCS_OBJECTIVE_TYPE_MAXIMIZE) - cmp = -cmp; - if (*result_ret == CCS_COMPARISON_EQUIVALENT) - *result_ret = (ccs_comparison_t)cmp; - else if (*result_ret != cmp) { - *result_ret = CCS_COMPARISON_NOT_COMPARABLE; - return CCS_RESULT_SUCCESS; - } - } - } - return CCS_RESULT_SUCCESS; -} diff --git a/src/evaluation_binding.c b/src/evaluation_binding.c new file mode 100644 index 00000000..34c933ea --- /dev/null +++ b/src/evaluation_binding.c @@ -0,0 +1,121 @@ +#include "cconfigspace_internal.h" +#include "evaluation_binding_internal.h" + +static inline _ccs_evaluation_binding_ops_t * +ccs_evaluation_binding_get_ops(ccs_evaluation_binding_t binding) +{ + return (_ccs_evaluation_binding_ops_t *)binding->obj.ops; +} + +ccs_result_t +ccs_evaluation_binding_get_objective_space( + ccs_evaluation_binding_t evaluation, + ccs_objective_space_t *objective_space_ret) +{ + CCS_CHECK_EVALUATION_BINDING(evaluation); + CCS_CHECK_PTR(objective_space_ret); + *objective_space_ret = evaluation->data->objective_space; + return CCS_RESULT_SUCCESS; +} + +ccs_result_t +ccs_evaluation_binding_get_result( + ccs_evaluation_binding_t evaluation, + ccs_evaluation_result_t *result_ret) +{ + CCS_CHECK_EVALUATION_BINDING(evaluation); + CCS_CHECK_PTR(result_ret); + *result_ret = evaluation->data->result; + return CCS_RESULT_SUCCESS; +} + +ccs_result_t +ccs_evaluation_binding_check( + ccs_evaluation_binding_t evaluation, + ccs_bool_t *is_valid_ret) +{ + CCS_CHECK_EVALUATION_BINDING(evaluation); + CCS_VALIDATE(ccs_objective_space_check_evaluation( + evaluation->data->objective_space, evaluation, is_valid_ret)); + return CCS_RESULT_SUCCESS; +} + +ccs_result_t +ccs_evaluation_binding_get_objective_value( + ccs_evaluation_binding_t evaluation, + size_t index, + ccs_datum_t *value_ret) +{ + CCS_CHECK_EVALUATION_BINDING(evaluation); + CCS_CHECK_PTR(value_ret); + ccs_expression_t expression; + ccs_objective_type_t type; + CCS_VALIDATE(ccs_objective_space_get_objective( + evaluation->data->objective_space, index, &expression, &type)); + CCS_VALIDATE(ccs_expression_eval( + expression, 1, (ccs_binding_t *)&evaluation, value_ret)); + return CCS_RESULT_SUCCESS; +} + +ccs_result_t +ccs_evaluation_get_objective_values( + ccs_evaluation_binding_t evaluation, + size_t num_values, + ccs_datum_t *values, + size_t *num_values_ret) +{ + CCS_CHECK_EVALUATION_BINDING(evaluation); + CCS_CHECK_ARY(num_values, values); + CCS_REFUTE(!values && !num_values_ret, CCS_RESULT_ERROR_INVALID_VALUE); + size_t count; + CCS_VALIDATE(ccs_objective_space_get_objectives( + evaluation->data->objective_space, 0, NULL, NULL, &count)); + if (values) { + CCS_REFUTE(count < num_values, CCS_RESULT_ERROR_INVALID_VALUE); + for (size_t i = 0; i < count; i++) { + ccs_expression_t expression; + ccs_objective_type_t type; + + CCS_VALIDATE(ccs_objective_space_get_objective( + evaluation->data->objective_space, i, + &expression, &type)); + CCS_VALIDATE(ccs_expression_eval( + expression, 1, (ccs_binding_t *)&evaluation, + values + i)); + } + for (size_t i = count; i < num_values; i++) + values[i] = ccs_none; + } + if (num_values_ret) + *num_values_ret = count; + return CCS_RESULT_SUCCESS; +} + +ccs_result_t +ccs_evaluation_binding_compare( + ccs_evaluation_binding_t evaluation, + ccs_evaluation_binding_t other_evaluation, + ccs_comparison_t *result_ret) +{ + CCS_CHECK_EVALUATION_BINDING(evaluation); + CCS_CHECK_EVALUATION_BINDING(other_evaluation); + CCS_REFUTE(evaluation->obj.type != other_evaluation->obj.type, + CCS_RESULT_ERROR_INVALID_OBJECT); + CCS_CHECK_PTR(result_ret); + if (evaluation == other_evaluation) { + *result_ret = CCS_COMPARISON_EQUIVALENT; + return CCS_RESULT_SUCCESS; + } + CCS_REFUTE( + evaluation->data->result || other_evaluation->data->result, + CCS_RESULT_ERROR_INVALID_OBJECT); + CCS_REFUTE( + evaluation->data->objective_space != + other_evaluation->data->objective_space, + CCS_RESULT_ERROR_INVALID_OBJECT); + + _ccs_evaluation_binding_ops_t *ops = ccs_evaluation_binding_get_ops(evaluation); + CCS_VALIDATE(ops->compare( + evaluation, other_evaluation, result_ret)); + return CCS_RESULT_SUCCESS; +} diff --git a/src/evaluation_binding_internal.h b/src/evaluation_binding_internal.h new file mode 100644 index 00000000..6b7a6a02 --- /dev/null +++ b/src/evaluation_binding_internal.h @@ -0,0 +1,92 @@ +#ifndef _EVALUATION_BINDING_INTERNAL_H +#define _EVALUATION_BINDING_INTERNAL_H + +typedef struct _ccs_evaluation_binding_data_s _ccs_evaluation_binding_data_t; + +struct _ccs_evaluation_binding_ops_s { + _ccs_object_ops_t obj_ops; + + ccs_result_t (*hash)(ccs_binding_t binding, ccs_hash_t *hash_ret); + + ccs_result_t ( + *cmp)(ccs_binding_t binding, ccs_binding_t other, int *cmp_ret); + + ccs_result_t (*compare)( + ccs_evaluation_binding_t evaluation, + ccs_evaluation_binding_t other_evaluation, + ccs_comparison_t *result_ret); +}; +typedef struct _ccs_evaluation_binding_ops_s _ccs_evaluation_binding_ops_t; + +struct _ccs_evaluation_binding_data_s { + ccs_objective_space_t objective_space; + size_t num_values; + ccs_datum_t *values; + ccs_evaluation_result_t result; +}; + +struct _ccs_evaluation_binding_s { + _ccs_object_internal_t obj; + _ccs_evaluation_binding_data_t *data; +}; + +static inline int +_numeric_compare(const ccs_datum_t *a, const ccs_datum_t *b) +{ + if (a->type == CCS_DATA_TYPE_FLOAT) { + return a->value.f < b->value.f ? -1 : + a->value.f > b->value.f ? 1 : + 0; + } else { + return a->value.i < b->value.i ? -1 : + a->value.i > b->value.i ? 1 : + 0; + } +} + +static inline ccs_result_t +_ccs_evaluation_binding_compare( + ccs_evaluation_binding_t evaluation, + ccs_evaluation_binding_t other_evaluation, + ccs_comparison_t *result_ret) +{ + size_t count; + CCS_VALIDATE(ccs_objective_space_get_objectives( + evaluation->data->objective_space, 0, NULL, NULL, &count)); + *result_ret = CCS_COMPARISON_EQUIVALENT; + for (size_t i = 0; i < count; i++) { + ccs_expression_t expression; + ccs_objective_type_t type; + ccs_datum_t values[2]; + int cmp; + + CCS_VALIDATE(ccs_objective_space_get_objective( + evaluation->data->objective_space, i, &expression, + &type)); + CCS_VALIDATE(ccs_expression_eval( + expression, 1, (ccs_binding_t *)&evaluation, values)); + CCS_VALIDATE(ccs_expression_eval( + expression, 1, (ccs_binding_t *)&other_evaluation, + values + 1)); + if ((values[0].type != CCS_DATA_TYPE_INT && + values[0].type != CCS_DATA_TYPE_FLOAT) || + values[0].type != values[1].type) { + *result_ret = CCS_COMPARISON_NOT_COMPARABLE; + return CCS_RESULT_SUCCESS; + } + cmp = _numeric_compare(values, values + 1); + if (cmp) { + if (type == CCS_OBJECTIVE_TYPE_MAXIMIZE) + cmp = -cmp; + if (*result_ret == CCS_COMPARISON_EQUIVALENT) + *result_ret = (ccs_comparison_t)cmp; + else if (*result_ret != cmp) { + *result_ret = CCS_COMPARISON_NOT_COMPARABLE; + return CCS_RESULT_SUCCESS; + } + } + } + return CCS_RESULT_SUCCESS; +} + +#endif // _EVALUATION_BINDING_INTERNAL_H diff --git a/src/evaluation_internal.h b/src/evaluation_internal.h index 8072a204..2e4d83f5 100644 --- a/src/evaluation_internal.h +++ b/src/evaluation_internal.h @@ -14,6 +14,11 @@ struct _ccs_evaluation_ops_s { ccs_evaluation_t evaluation, ccs_evaluation_t other, int *cmp_ret); + + ccs_result_t (*compare)( + ccs_evaluation_t evaluation, + ccs_evaluation_t other_evaluation, + ccs_comparison_t *result_ret); }; typedef struct _ccs_evaluation_ops_s _ccs_evaluation_ops_t; diff --git a/src/features_evaluation.c b/src/features_evaluation.c index 6a8cb9c0..a47a910d 100644 --- a/src/features_evaluation.c +++ b/src/features_evaluation.c @@ -1,4 +1,5 @@ #include "cconfigspace_internal.h" +#include "evaluation_binding_internal.h" #include "features_evaluation_internal.h" #include "configuration_internal.h" #include "features_internal.h" @@ -175,12 +176,34 @@ _ccs_features_evaluation_cmp( return CCS_RESULT_SUCCESS; } +static ccs_result_t +_ccs_features_evaluation_compare( + ccs_features_evaluation_t evaluation, + ccs_features_evaluation_t other_evaluation, + ccs_comparison_t *result_ret) +{ + int eql; + CCS_VALIDATE(ccs_binding_cmp( + (ccs_binding_t)evaluation->data->features, + (ccs_binding_t)other_evaluation->data->features, &eql)); + if (0 != eql) { + *result_ret = CCS_COMPARISON_NOT_COMPARABLE; + return CCS_RESULT_SUCCESS; + } + CCS_VALIDATE(_ccs_evaluation_binding_compare( + (ccs_evaluation_binding_t)evaluation, + (ccs_evaluation_binding_t)other_evaluation, + result_ret)); + return CCS_RESULT_SUCCESS; +} + static _ccs_features_evaluation_ops_t _features_evaluation_ops = { {&_ccs_features_evaluation_del, &_ccs_features_evaluation_serialize_size, &_ccs_features_evaluation_serialize}, &_ccs_features_evaluation_hash, - &_ccs_features_evaluation_cmp}; + &_ccs_features_evaluation_cmp, + &_ccs_features_evaluation_compare}; ccs_result_t ccs_create_features_evaluation( @@ -257,18 +280,6 @@ ccs_create_features_evaluation( return err; } -ccs_result_t -ccs_features_evaluation_get_objective_space( - ccs_features_evaluation_t evaluation, - ccs_objective_space_t *objective_space_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_FEATURES_EVALUATION); - CCS_VALIDATE(_ccs_binding_get_context( - (ccs_binding_t)evaluation, - (ccs_context_t *)objective_space_ret)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_features_evaluation_get_configuration( ccs_features_evaluation_t evaluation, @@ -290,160 +301,3 @@ ccs_features_evaluation_get_features( *features_ret = evaluation->data->features; return CCS_RESULT_SUCCESS; } - -ccs_result_t -ccs_features_evaluation_get_result( - ccs_features_evaluation_t evaluation, - ccs_evaluation_result_t *result_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_FEATURES_EVALUATION); - CCS_CHECK_PTR(result_ret); - *result_ret = evaluation->data->result; - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_features_evaluation_check( - ccs_features_evaluation_t evaluation, - ccs_bool_t *is_valid_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_FEATURES_EVALUATION); - CCS_VALIDATE(ccs_objective_space_check_evaluation( - evaluation->data->objective_space, (ccs_evaluation_t)evaluation, - is_valid_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_features_evaluation_get_objective_value( - ccs_features_evaluation_t evaluation, - size_t index, - ccs_datum_t *value_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_FEATURES_EVALUATION); - CCS_CHECK_PTR(value_ret); - ccs_expression_t expression; - ccs_objective_type_t type; - CCS_VALIDATE(ccs_objective_space_get_objective( - evaluation->data->objective_space, index, &expression, &type)); - CCS_VALIDATE(ccs_expression_eval( - expression, 1, (ccs_binding_t *)&evaluation, value_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_features_evaluation_get_objective_values( - ccs_features_evaluation_t evaluation, - size_t num_values, - ccs_datum_t *values, - size_t *num_values_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_FEATURES_EVALUATION); - CCS_CHECK_ARY(num_values, values); - CCS_REFUTE(!values && !num_values_ret, CCS_RESULT_ERROR_INVALID_VALUE); - size_t count; - CCS_VALIDATE(ccs_objective_space_get_objectives( - evaluation->data->objective_space, 0, NULL, NULL, &count)); - if (values) { - CCS_REFUTE(count < num_values, CCS_RESULT_ERROR_INVALID_VALUE); - for (size_t i = 0; i < count; i++) { - ccs_expression_t expression; - ccs_objective_type_t type; - - CCS_VALIDATE(ccs_objective_space_get_objective( - evaluation->data->objective_space, i, - &expression, &type)); - CCS_VALIDATE(ccs_expression_eval( - expression, 1, (ccs_binding_t *)&evaluation, - values + i)); - } - for (size_t i = count; i < num_values; i++) - values[i] = ccs_none; - } - if (num_values_ret) - *num_values_ret = count; - return CCS_RESULT_SUCCESS; -} - -static inline int -_numeric_compare(const ccs_datum_t *a, const ccs_datum_t *b) -{ - if (a->type == CCS_DATA_TYPE_FLOAT) { - return a->value.f < b->value.f ? -1 : - a->value.f > b->value.f ? 1 : - 0; - } else { - return a->value.i < b->value.i ? -1 : - a->value.i > b->value.i ? 1 : - 0; - } -} - -// Could be using memoization here. -ccs_result_t -ccs_features_evaluation_compare( - ccs_features_evaluation_t evaluation, - ccs_features_evaluation_t other_evaluation, - ccs_comparison_t *result_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_FEATURES_EVALUATION); - CCS_CHECK_OBJ(other_evaluation, CCS_OBJECT_TYPE_FEATURES_EVALUATION); - CCS_CHECK_PTR(result_ret); - if (evaluation == other_evaluation) { - *result_ret = CCS_COMPARISON_EQUIVALENT; - return CCS_RESULT_SUCCESS; - } - CCS_REFUTE( - evaluation->data->result || other_evaluation->data->result, - CCS_RESULT_ERROR_INVALID_OBJECT); - CCS_REFUTE( - evaluation->data->objective_space != - other_evaluation->data->objective_space, - CCS_RESULT_ERROR_INVALID_OBJECT); - size_t count; - int eql; - CCS_VALIDATE(ccs_objective_space_get_objectives( - evaluation->data->objective_space, 0, NULL, NULL, &count)); - CCS_VALIDATE(ccs_binding_cmp( - (ccs_binding_t)evaluation->data->features, - (ccs_binding_t)other_evaluation->data->features, &eql)); - if (0 != eql) { - *result_ret = CCS_COMPARISON_NOT_COMPARABLE; - return CCS_RESULT_SUCCESS; - } - - *result_ret = CCS_COMPARISON_EQUIVALENT; - for (size_t i = 0; i < count; i++) { - ccs_expression_t expression; - ccs_objective_type_t type; - ccs_datum_t values[2]; - int cmp; - - CCS_VALIDATE(ccs_objective_space_get_objective( - evaluation->data->objective_space, i, &expression, - &type)); - CCS_VALIDATE(ccs_expression_eval( - expression, 1, (ccs_binding_t *)&evaluation, values)); - CCS_VALIDATE(ccs_expression_eval( - expression, 1, (ccs_binding_t *)&other_evaluation, - values + 1)); - if ((values[0].type != CCS_DATA_TYPE_INT && - values[0].type != CCS_DATA_TYPE_FLOAT) || - values[0].type != values[1].type) { - *result_ret = CCS_COMPARISON_NOT_COMPARABLE; - return CCS_RESULT_SUCCESS; - } - cmp = _numeric_compare(values, values + 1); - if (cmp) { - if (type == CCS_OBJECTIVE_TYPE_MAXIMIZE) - cmp = -cmp; - if (*result_ret == CCS_COMPARISON_EQUIVALENT) - *result_ret = (ccs_comparison_t)cmp; - else if (*result_ret != cmp) { - *result_ret = CCS_COMPARISON_NOT_COMPARABLE; - return CCS_RESULT_SUCCESS; - } - } - } - return CCS_RESULT_SUCCESS; -} diff --git a/src/features_evaluation_internal.h b/src/features_evaluation_internal.h index 4a9106c1..cc1fd683 100644 --- a/src/features_evaluation_internal.h +++ b/src/features_evaluation_internal.h @@ -16,6 +16,11 @@ struct _ccs_features_evaluation_ops_s { ccs_features_evaluation_t features_evaluation, ccs_features_evaluation_t other, int *cmp_ret); + + ccs_result_t (*compare)( + ccs_features_evaluation_t evaluation, + ccs_features_evaluation_t other_evaluation, + ccs_comparison_t *result_ret); }; typedef struct _ccs_features_evaluation_ops_s _ccs_features_evaluation_ops_t; diff --git a/src/features_tuner_random.c b/src/features_tuner_random.c index 544dc862..add81718 100644 --- a/src/features_tuner_random.c +++ b/src/features_tuner_random.c @@ -196,8 +196,8 @@ _ccs_features_tuner_random_tell( ccs_result_t err; for (size_t i = 0; i < num_evaluations; i++) { ccs_evaluation_result_t result; - CCS_VALIDATE(ccs_features_evaluation_get_result( - evaluations[i], &result)); + CCS_VALIDATE(ccs_evaluation_binding_get_result( + (ccs_evaluation_binding_t)evaluations[i], &result)); if (result == CCS_RESULT_SUCCESS) { int discard = 0; UT_array *tmp; @@ -220,8 +220,9 @@ _ccs_features_tuner_random_tell( utarray_next(d->old_optima, eval))) { if (!discard) { ccs_comparison_t cmp; - err = ccs_features_evaluation_compare( - evaluations[i], *eval, &cmp); + err = ccs_evaluation_binding_compare( + (ccs_evaluation_binding_t)evaluations[i], + (ccs_evaluation_binding_t)*eval, &cmp); if (err) discard = 1; else diff --git a/src/objective_space.c b/src/objective_space.c index 1ce0be72..de24297b 100644 --- a/src/objective_space.c +++ b/src/objective_space.c @@ -1,6 +1,6 @@ #include "cconfigspace_internal.h" #include "objective_space_internal.h" -#include "evaluation_internal.h" +#include "evaluation_binding_internal.h" #include "expression_internal.h" static ccs_result_t @@ -272,9 +272,9 @@ ccs_create_objective_space( static inline ccs_result_t _check_evaluation( - ccs_objective_space_t objective_space, - ccs_evaluation_t evaluation, - ccs_bool_t *is_valid_ret) + ccs_objective_space_t objective_space, + ccs_evaluation_binding_t evaluation, + ccs_bool_t *is_valid_ret) { ccs_parameter_t *parameters = objective_space->data->parameters; size_t num_parameters = objective_space->data->num_parameters; @@ -292,12 +292,12 @@ _check_evaluation( ccs_result_t ccs_objective_space_check_evaluation( - ccs_objective_space_t objective_space, - ccs_evaluation_t evaluation, - ccs_bool_t *is_valid_ret) + ccs_objective_space_t objective_space, + ccs_evaluation_binding_t evaluation, + ccs_bool_t *is_valid_ret) { CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); - CCS_CHECK_EVALUATION(evaluation); + CCS_CHECK_EVALUATION_BINDING(evaluation); CCS_REFUTE( evaluation->data->objective_space != objective_space, CCS_RESULT_ERROR_INVALID_EVALUATION); diff --git a/src/tree_evaluation.c b/src/tree_evaluation.c index b9a392ed..2ae74f39 100644 --- a/src/tree_evaluation.c +++ b/src/tree_evaluation.c @@ -1,4 +1,5 @@ #include "cconfigspace_internal.h" +#include "evaluation_binding_internal.h" #include "tree_evaluation_internal.h" #include "tree_configuration_internal.h" #include "objective_space_internal.h" @@ -157,11 +158,25 @@ _ccs_tree_evaluation_cmp( return CCS_RESULT_SUCCESS; } +static ccs_result_t +_ccs_tree_evaluation_compare( + ccs_tree_evaluation_t evaluation, + ccs_tree_evaluation_t other, + ccs_comparison_t *result_ret) +{ + CCS_VALIDATE(_ccs_evaluation_binding_compare( + (ccs_evaluation_binding_t)evaluation, + (ccs_evaluation_binding_t)other, + result_ret)); + return CCS_RESULT_SUCCESS; +} + static _ccs_tree_evaluation_ops_t _evaluation_ops = { {&_ccs_tree_evaluation_del, &_ccs_tree_evaluation_serialize_size, &_ccs_tree_evaluation_serialize}, &_ccs_tree_evaluation_hash, - &_ccs_tree_evaluation_cmp}; + &_ccs_tree_evaluation_cmp, + &_ccs_tree_evaluation_compare}; ccs_result_t ccs_create_tree_evaluation( @@ -227,18 +242,6 @@ ccs_create_tree_evaluation( return err; } -ccs_result_t -ccs_tree_evaluation_get_objective_space( - ccs_tree_evaluation_t evaluation, - ccs_objective_space_t *objective_space_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_TREE_EVALUATION); - CCS_VALIDATE(_ccs_binding_get_context( - (ccs_binding_t)evaluation, - (ccs_context_t *)objective_space_ret)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_tree_evaluation_get_configuration( ccs_tree_evaluation_t evaluation, @@ -249,153 +252,3 @@ ccs_tree_evaluation_get_configuration( *configuration_ret = evaluation->data->configuration; return CCS_RESULT_SUCCESS; } - -ccs_result_t -ccs_tree_evaluation_get_result( - ccs_tree_evaluation_t evaluation, - ccs_evaluation_result_t *result_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_TREE_EVALUATION); - CCS_CHECK_PTR(result_ret); - *result_ret = evaluation->data->result; - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_tree_evaluation_check( - ccs_tree_evaluation_t evaluation, - ccs_bool_t *is_valid_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_TREE_EVALUATION); - CCS_VALIDATE(ccs_objective_space_check_evaluation( - evaluation->data->objective_space, (ccs_evaluation_t)evaluation, - is_valid_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_tree_evaluation_get_objective_value( - ccs_tree_evaluation_t evaluation, - size_t index, - ccs_datum_t *value_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_TREE_EVALUATION); - CCS_CHECK_PTR(value_ret); - ccs_expression_t expression; - ccs_objective_type_t type; - CCS_VALIDATE(ccs_objective_space_get_objective( - evaluation->data->objective_space, index, &expression, &type)); - CCS_VALIDATE(ccs_expression_eval( - expression, 1, (ccs_binding_t *)&evaluation, value_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_tree_evaluation_get_objective_values( - ccs_tree_evaluation_t evaluation, - size_t num_values, - ccs_datum_t *values, - size_t *num_values_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_TREE_EVALUATION); - CCS_CHECK_ARY(num_values, values); - CCS_REFUTE(!values && !num_values_ret, CCS_RESULT_ERROR_INVALID_VALUE); - size_t count; - CCS_VALIDATE(ccs_objective_space_get_objectives( - evaluation->data->objective_space, 0, NULL, NULL, &count)); - if (values) { - CCS_REFUTE(count < num_values, CCS_RESULT_ERROR_INVALID_VALUE); - for (size_t i = 0; i < count; i++) { - ccs_expression_t expression; - ccs_objective_type_t type; - - CCS_VALIDATE(ccs_objective_space_get_objective( - evaluation->data->objective_space, i, - &expression, &type)); - CCS_VALIDATE(ccs_expression_eval( - expression, 1, (ccs_binding_t *)&evaluation, - values + i)); - } - for (size_t i = count; i < num_values; i++) - values[i] = ccs_none; - } - if (num_values_ret) - *num_values_ret = count; - return CCS_RESULT_SUCCESS; -} - -static inline int -_numeric_compare(const ccs_datum_t *a, const ccs_datum_t *b) -{ - if (a->type == CCS_DATA_TYPE_FLOAT) { - return a->value.f < b->value.f ? -1 : - a->value.f > b->value.f ? 1 : - 0; - } else { - return a->value.i < b->value.i ? -1 : - a->value.i > b->value.i ? 1 : - 0; - } -} - -// Could be using memoization here. -ccs_result_t -ccs_tree_evaluation_compare( - ccs_tree_evaluation_t evaluation, - ccs_tree_evaluation_t other_evaluation, - ccs_comparison_t *result_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_TREE_EVALUATION); - CCS_CHECK_OBJ(other_evaluation, CCS_OBJECT_TYPE_TREE_EVALUATION); - CCS_CHECK_PTR(result_ret); - if (evaluation == other_evaluation) { - *result_ret = CCS_COMPARISON_EQUIVALENT; - return CCS_RESULT_SUCCESS; - } - CCS_REFUTE( - evaluation->data->result || other_evaluation->data->result, - CCS_RESULT_ERROR_INVALID_OBJECT); - CCS_REFUTE( - evaluation->data->objective_space != - other_evaluation->data->objective_space, - CCS_RESULT_ERROR_INVALID_OBJECT); - size_t count; - CCS_VALIDATE(ccs_objective_space_get_objectives( - evaluation->data->objective_space, 0, NULL, NULL, &count)); - *result_ret = CCS_COMPARISON_EQUIVALENT; - for (size_t i = 0; i < count; i++) { - ccs_expression_t expression; - ccs_objective_type_t type; - ccs_datum_t values[2]; - int cmp; - - CCS_VALIDATE(ccs_objective_space_get_objective( - evaluation->data->objective_space, i, &expression, - &type)); - CCS_VALIDATE(ccs_expression_eval( - expression, 1, (ccs_binding_t *)&evaluation, values)); - CCS_VALIDATE(ccs_expression_eval( - expression, 1, (ccs_binding_t *)&other_evaluation, - values + 1)); - // Maybe relax to allow comparing Numerical values of different - // types. - if ((values[0].type != CCS_DATA_TYPE_INT && - values[0].type != CCS_DATA_TYPE_FLOAT) || - values[0].type != values[1].type) { - *result_ret = CCS_COMPARISON_NOT_COMPARABLE; - return CCS_RESULT_SUCCESS; - } - cmp = _numeric_compare(values, values + 1); - if (cmp) { - if (type == CCS_OBJECTIVE_TYPE_MAXIMIZE) - cmp = -cmp; - if (*result_ret == CCS_COMPARISON_EQUIVALENT) - *result_ret = (ccs_comparison_t)cmp; - else if (*result_ret != cmp) { - *result_ret = CCS_COMPARISON_NOT_COMPARABLE; - return CCS_RESULT_SUCCESS; - } - } - } - return CCS_RESULT_SUCCESS; -} diff --git a/src/tree_evaluation_internal.h b/src/tree_evaluation_internal.h index 9c6cf8ab..ec5f5847 100644 --- a/src/tree_evaluation_internal.h +++ b/src/tree_evaluation_internal.h @@ -16,6 +16,11 @@ struct _ccs_tree_evaluation_ops_s { ccs_tree_evaluation_t tree_evaluation, ccs_tree_evaluation_t other, int *cmp_ret); + + ccs_result_t (*compare)( + ccs_tree_evaluation_t evaluation, + ccs_tree_evaluation_t other_evaluation, + ccs_comparison_t *result_ret); }; typedef struct _ccs_tree_evaluation_ops_s _ccs_tree_evaluation_ops_t; diff --git a/src/tree_tuner_random.c b/src/tree_tuner_random.c index 92265ae5..f38d5259 100644 --- a/src/tree_tuner_random.c +++ b/src/tree_tuner_random.c @@ -188,8 +188,8 @@ _ccs_tree_tuner_random_tell( ccs_result_t err; for (size_t i = 0; i < num_evaluations; i++) { ccs_evaluation_result_t result; - CCS_VALIDATE(ccs_tree_evaluation_get_result( - evaluations[i], &result)); + CCS_VALIDATE(ccs_evaluation_binding_get_result( + (ccs_evaluation_binding_t)evaluations[i], &result)); if (!result) { int discard = 0; UT_array *tmp; @@ -212,8 +212,9 @@ _ccs_tree_tuner_random_tell( d->old_optima, eval))) { if (!discard) { ccs_comparison_t cmp; - err = ccs_tree_evaluation_compare( - evaluations[i], *eval, &cmp); + err = ccs_evaluation_binding_compare( + (ccs_evaluation_binding_t)evaluations[i], + (ccs_evaluation_binding_t)*eval, &cmp); if (err) discard = 1; else diff --git a/src/tuner_random.c b/src/tuner_random.c index dd8208ab..52a4521d 100644 --- a/src/tuner_random.c +++ b/src/tuner_random.c @@ -188,7 +188,8 @@ _ccs_tuner_random_tell( for (size_t i = 0; i < num_evaluations; i++) { ccs_evaluation_result_t result; CCS_VALIDATE( - ccs_evaluation_get_result(evaluations[i], &result)); + ccs_evaluation_binding_get_result( + (ccs_evaluation_binding_t)evaluations[i], &result)); if (!result) { int discard = 0; UT_array *tmp; @@ -211,8 +212,9 @@ _ccs_tuner_random_tell( d->old_optima, eval))) { if (!discard) { ccs_comparison_t cmp; - err = ccs_evaluation_compare( - evaluations[i], *eval, &cmp); + err = ccs_evaluation_binding_compare( + (ccs_evaluation_binding_t)evaluations[i], + (ccs_evaluation_binding_t)*eval, &cmp); if (err) discard = 1; else diff --git a/tests/test_random_features_tuner.c b/tests/test_random_features_tuner.c index b61954c2..8c0758de 100644 --- a/tests/test_random_features_tuner.c +++ b/tests/test_random_features_tuner.c @@ -137,8 +137,8 @@ test(void) for (size_t i = 0; i < 50; i++) { ccs_datum_t res; - err = ccs_features_evaluation_get_objective_value( - history[i], 0, &res); + err = ccs_evaluation_binding_get_objective_value( + (ccs_evaluation_binding_t)history[i], 0, &res); assert(err == CCS_RESULT_SUCCESS); if (res.value.f < min_on.value.f) min_on.value.f = res.value.f; @@ -151,8 +151,8 @@ test(void) for (size_t i = 0; i < 50; i++) { ccs_datum_t res; - err = ccs_features_evaluation_get_objective_value( - history[i], 0, &res); + err = ccs_evaluation_binding_get_objective_value( + (ccs_evaluation_binding_t)history[i], 0, &res); assert(err == CCS_RESULT_SUCCESS); if (res.value.f < min_off.value.f) min_off.value.f = res.value.f; @@ -162,13 +162,15 @@ test(void) err = ccs_features_tuner_get_optima( tuner, features_on, 1, &evaluation, NULL); assert(err == CCS_RESULT_SUCCESS); - err = ccs_features_evaluation_get_objective_value(evaluation, 0, &res); + err = ccs_evaluation_binding_get_objective_value( + (ccs_evaluation_binding_t)evaluation, 0, &res); assert(res.value.f == min_on.value.f); err = ccs_features_tuner_get_optima( tuner, features_off, 1, &evaluation, NULL); assert(err == CCS_RESULT_SUCCESS); - err = ccs_features_evaluation_get_objective_value(evaluation, 0, &res); + err = ccs_evaluation_binding_get_objective_value( + (ccs_evaluation_binding_t)evaluation, 0, &res); assert(res.value.f == min_off.value.f); /* Test (de)serialization */ diff --git a/tests/test_random_tree_tuner.c b/tests/test_random_tree_tuner.c index 3eb799be..914a9eb2 100644 --- a/tests/test_random_tree_tuner.c +++ b/tests/test_random_tree_tuner.c @@ -121,8 +121,8 @@ test(void) for (size_t i = 0; i < 100; i++) { ccs_datum_t res; - err = ccs_tree_evaluation_get_objective_value( - history[i], 0, &res); + err = ccs_evaluation_binding_get_objective_value( + (ccs_evaluation_binding_t)history[i], 0, &res); assert(err == CCS_RESULT_SUCCESS); if (res.value.f > max.value.f) max.value.f = res.value.f; @@ -132,7 +132,8 @@ test(void) ccs_datum_t res; err = ccs_tree_tuner_get_optima(tuner, 1, &evaluation, NULL); assert(err == CCS_RESULT_SUCCESS); - err = ccs_tree_evaluation_get_objective_value(evaluation, 0, &res); + err = ccs_evaluation_binding_get_objective_value( + (ccs_evaluation_binding_t)evaluation, 0, &res); assert(res.value.f == max.value.f); /* Test (de)serialization */ diff --git a/tests/test_random_tuner.c b/tests/test_random_tuner.c index 0657d53e..63168fa7 100644 --- a/tests/test_random_tuner.c +++ b/tests/test_random_tuner.c @@ -84,7 +84,8 @@ test(void) for (size_t i = 0; i < 100; i++) { ccs_datum_t res; - err = ccs_evaluation_get_objective_value(history[i], 0, &res); + err = ccs_evaluation_binding_get_objective_value( + (ccs_evaluation_binding_t)history[i], 0, &res); assert(err == CCS_RESULT_SUCCESS); if (res.value.f < min.value.f) min.value.f = res.value.f; @@ -94,7 +95,8 @@ test(void) ccs_datum_t res; err = ccs_tuner_get_optima(tuner, 1, &evaluation, NULL); assert(err == CCS_RESULT_SUCCESS); - err = ccs_evaluation_get_objective_value(evaluation, 0, &res); + err = ccs_evaluation_binding_get_objective_value( + (ccs_evaluation_binding_t)evaluation, 0, &res); assert(res.value.f == min.value.f); /* Test (de)serialization */