Skip to content

Commit

Permalink
Refactoring evaluations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerilk committed Mar 23, 2024
1 parent cfa3a22 commit 1c501b0
Show file tree
Hide file tree
Showing 38 changed files with 685 additions and 1,317 deletions.
1 change: 1 addition & 0 deletions bindings/python/cconfigspace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from .features_space import *
from .features import *
from .objective_space import *
from .evaluation_binding import *
from .evaluation import *
from .features_evaluation import *
from .tuner import *
Expand Down
1 change: 1 addition & 0 deletions bindings/python/cconfigspace/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __str__(self):
ccs_features_space = ccs_object
ccs_features = ccs_object
ccs_objective_space = ccs_object
ccs_evaluation_binding = ccs_object
ccs_evaluation = ccs_object
ccs_features_evaluation = ccs_object
ccs_tuner = ccs_object
Expand Down
73 changes: 3 additions & 70 deletions bindings/python/cconfigspace/evaluation.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
import ctypes as ct
from .base import Object, Error, CEnumeration, Result, ccs_evaluation_result, _ccs_get_function, ccs_context, ccs_parameter, ccs_configuration, Datum, DatumFix, ccs_objective_space, ccs_evaluation, ccs_bool
from .binding import Binding
from .base import Error, Datum, Result, _ccs_get_function, ccs_configuration, ccs_evaluation, ccs_objective_space, ccs_evaluation_result
from .evaluation_binding import EvaluationBinding
from .configuration import Configuration
from .objective_space import ObjectiveSpace

class Comparison(CEnumeration):
_members_ = [
('BETTER', -1),
('EQUIVALENT', 0),
('WORSE', 1),
('NOT_COMPARABLE', 2) ]

ccs_create_evaluation = _ccs_get_function("ccs_create_evaluation", [ccs_objective_space, ccs_configuration, ccs_evaluation_result, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ccs_evaluation)])
ccs_evaluation_get_objective_space = _ccs_get_function("ccs_evaluation_get_objective_space", [ccs_evaluation, ct.POINTER(ccs_objective_space)])
ccs_evaluation_get_configuration = _ccs_get_function("ccs_evaluation_get_configuration", [ccs_evaluation, ct.POINTER(ccs_configuration)])
ccs_evaluation_get_result = _ccs_get_function("ccs_evaluation_get_result", [ccs_evaluation, ct.POINTER(ccs_evaluation_result)])
ccs_evaluation_get_objective_value = _ccs_get_function("ccs_evaluation_get_objective_value", [ccs_evaluation, ct.c_size_t, ct.POINTER(Datum)])
ccs_evaluation_get_objective_values = _ccs_get_function("ccs_evaluation_get_objective_values", [ccs_evaluation, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ct.c_size_t)])
ccs_evaluation_compare = _ccs_get_function("ccs_evaluation_compare", [ccs_evaluation, ccs_evaluation, ct.POINTER(Comparison)])
ccs_evaluation_check = _ccs_get_function("ccs_evaluation_check", [ccs_evaluation, ct.POINTER(ccs_bool)])

class Evaluation(Binding):
class Evaluation(EvaluationBinding):
def __init__(self, handle = None, retain = False, auto_release = True,
objective_space = None, configuration = None, result = Result.SUCCESS, values = None):
if handle is None:
Expand All @@ -44,16 +30,6 @@ def __init__(self, handle = None, retain = False, auto_release = True,
def from_handle(cls, handle, retain = True, auto_release = True):
return cls(handle = handle, retain = retain, auto_release = auto_release)

@property
def objective_space(self):
if hasattr(self, "_objective_space"):
return self._objective_space
v = ccs_objective_space()
res = ccs_evaluation_get_objective_space(self.handle, ct.byref(v))
Error.check(res)
self._objective_space = ObjectiveSpace.from_handle(v)
return self._objective_space

@property
def configuration(self):
if hasattr(self, "_configuration"):
Expand All @@ -63,46 +39,3 @@ def configuration(self):
Error.check(res)
self._configuration = Configuration.from_handle(v)
return self._configuration

@property
def result(self):
if hasattr(self, "_result"):
return self._result
v = ccs_evaluation_result()
res = ccs_evaluation_get_result(self.handle, ct.byref(v))
Error.check(res)
self._result = v.value
return self._result

@property
def num_objective_values(self):
if hasattr(self, "_num_objective_values"):
return self._num_objective_values
v = ct.c_size_t()
res = ccs_evaluation_get_objective_values(self.handle, 0, None, ct.byref(v))
Error.check(res)
self._num_objective_values = v.value
return self._num_objective_values

@property
def objective_values(self):
if hasattr(self, "_objective_values"):
return self._objective_values
sz = self.num_objective_values
v = (Datum * sz)()
res = ccs_evaluation_get_objective_values(self.handle, sz, v, None)
Error.check(res)
self._objective_values = tuple(x.value for x in v)
return self._objective_values

def compare(self, other):
v = Comparison(0)
res = ccs_evaluation_compare(self.handle, other.handle, ct.byref(v))
Error.check(res)
return v.value

def check(self):
valid = ccs_bool()
res = ccs_evaluation_check(self.handle, ct.byref(valid))
Error.check(res)
return False if valid.value == 0 else True
72 changes: 72 additions & 0 deletions bindings/python/cconfigspace/evaluation_binding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import ctypes as ct
from .base import Error, CEnumeration, Result, ccs_evaluation_result, _ccs_get_function, Datum, DatumFix, ccs_evaluation_binding, ccs_objective_space, ccs_bool
from .binding import Binding
from .objective_space import ObjectiveSpace

class Comparison(CEnumeration):
_members_ = [
('BETTER', -1),
('EQUIVALENT', 0),
('WORSE', 1),
('NOT_COMPARABLE', 2) ]

ccs_evaluation_binding_get_objective_space = _ccs_get_function("ccs_evaluation_binding_get_objective_space", [ccs_evaluation_binding, ct.POINTER(ccs_objective_space)])
ccs_evaluation_binding_get_result = _ccs_get_function("ccs_evaluation_binding_get_result", [ccs_evaluation_binding, ct.POINTER(ccs_evaluation_result)])
ccs_evaluation_binding_get_objective_values = _ccs_get_function("ccs_evaluation_binding_get_objective_values", [ccs_evaluation_binding, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ct.c_size_t)])
ccs_evaluation_binding_compare = _ccs_get_function("ccs_evaluation_binding_compare", [ccs_evaluation_binding, ccs_evaluation_binding, ct.POINTER(Comparison)])
ccs_evaluation_binding_check = _ccs_get_function("ccs_evaluation_binding_check", [ccs_evaluation_binding, ct.POINTER(ccs_bool)])

class EvaluationBinding(Binding):

@property
def objective_space(self):
if hasattr(self, "_objective_space"):
return self._objective_space
v = ccs_objective_space()
res = ccs_evaluation_binding_get_objective_space(self.handle, ct.byref(v))
Error.check(res)
self._objective_space = ObjectiveSpace.from_handle(v)
return self._objective_space

@property
def result(self):
if hasattr(self, "_result"):
return self._result
v = ccs_evaluation_result()
res = ccs_evaluation_binding_get_result(self.handle, ct.byref(v))
Error.check(res)
self._result = v.value
return self._result

@property
def num_objective_values(self):
if hasattr(self, "_num_objective_values"):
return self._num_objective_values
v = ct.c_size_t()
res = ccs_evaluation_binding_get_objective_values(self.handle, 0, None, ct.byref(v))
Error.check(res)
self._num_objective_values = v.value
return self._num_objective_values

@property
def objective_values(self):
if hasattr(self, "_objective_values"):
return self._objective_values
sz = self.num_objective_values
v = (Datum * sz)()
res = ccs_evaluation_binding_get_objective_values(self.handle, sz, v, None)
Error.check(res)
self._objective_values = tuple(x.value for x in v)
return self._objective_values

def compare(self, other):
v = Comparison(0)
res = ccs_evaluation_binding_compare(self.handle, other.handle, ct.byref(v))
Error.check(res)
return v.value

def check(self):
valid = ccs_bool()
res = ccs_evaluation_binding_check(self.handle, ct.byref(valid))
Error.check(res)
return False if valid.value == 0 else True
71 changes: 3 additions & 68 deletions bindings/python/cconfigspace/features_evaluation.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
import ctypes as ct
from .base import Object, Error, CEnumeration, Result, ccs_evaluation_result, _ccs_get_function, ccs_context, ccs_parameter, ccs_configuration_space, ccs_configuration, ccs_features_space, ccs_features, Datum, DatumFix, ccs_objective_space, ccs_features_evaluation, ccs_bool
from .context import Context
from .parameter import Parameter
from .configuration_space import ConfigurationSpace
from .base import Error, Datum, Result, _ccs_get_function, ccs_configuration, ccs_features, ccs_features_evaluation, ccs_objective_space, ccs_evaluation_result
from .evaluation_binding import EvaluationBinding
from .configuration import Configuration
from .features_space import FeaturesSpace
from .features import Features
from .objective_space import ObjectiveSpace
from .evaluation import Comparison
from .binding import Binding

ccs_create_features_evaluation = _ccs_get_function("ccs_create_features_evaluation", [ccs_objective_space, ccs_configuration, ccs_features, ccs_evaluation_result, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ccs_features_evaluation)])
ccs_features_evaluation_get_objective_space = _ccs_get_function("ccs_features_evaluation_get_objective_space", [ccs_features_evaluation, ct.POINTER(ccs_objective_space)])
ccs_features_evaluation_get_configuration = _ccs_get_function("ccs_features_evaluation_get_configuration", [ccs_features_evaluation, ct.POINTER(ccs_configuration)])
ccs_features_evaluation_get_features = _ccs_get_function("ccs_features_evaluation_get_features", [ccs_features_evaluation, ct.POINTER(ccs_features)])
ccs_features_evaluation_get_result = _ccs_get_function("ccs_features_evaluation_get_result", [ccs_features_evaluation, ct.POINTER(ccs_evaluation_result)])
ccs_features_evaluation_get_objective_value = _ccs_get_function("ccs_features_evaluation_get_objective_value", [ccs_features_evaluation, ct.c_size_t, ct.POINTER(Datum)])
ccs_features_evaluation_get_objective_values = _ccs_get_function("ccs_features_evaluation_get_objective_values", [ccs_features_evaluation, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ct.c_size_t)])
ccs_features_evaluation_compare = _ccs_get_function("ccs_features_evaluation_compare", [ccs_features_evaluation, ccs_features_evaluation, ct.POINTER(Comparison)])
ccs_features_evaluation_check = _ccs_get_function("ccs_features_evaluation_check", [ccs_features_evaluation, ct.POINTER(ccs_bool)])

class FeaturesEvaluation(Binding):
class FeaturesEvaluation(EvaluationBinding):
def __init__(self, handle = None, retain = False, auto_release = True,
objective_space = None, configuration = None, features = None, result = Result.SUCCESS, values = None):
if handle is None:
Expand All @@ -44,16 +32,6 @@ def __init__(self, handle = None, retain = False, auto_release = True,
def from_handle(cls, handle, retain = True, auto_release = True):
return cls(handle = handle, retain = retain, auto_release = auto_release)

@property
def objective_space(self):
if hasattr(self, "_objective_space"):
return self._objective_space
v = ccs_objective_space()
res = ccs_features_evaluation_get_objective_space(self.handle, ct.byref(v))
Error.check(res)
self._objective_space = ObjectiveSpace.from_handle(v)
return self._objective_space

@property
def configuration(self):
if hasattr(self, "_configuration"):
Expand All @@ -73,46 +51,3 @@ def features(self):
Error.check(res)
self._features = Features.from_handle(v)
return self._features

@property
def result(self):
if hasattr(self, "_result"):
return self._result
v = ccs_evaluation_result()
res = ccs_features_evaluation_get_result(self.handle, ct.byref(v))
Error.check(res)
self._result = v.value
return self._result

@property
def num_objective_values(self):
if hasattr(self, "_num_objective_values"):
return self._num_objective_values
v = ct.c_size_t()
res = ccs_features_evaluation_get_objective_values(self.handle, 0, None, ct.byref(v))
Error.check(res)
self._num_objective_values = v.value
return self._num_objective_values

@property
def objective_values(self):
if hasattr(self, "_objective_values"):
return self._objective_values
sz = self.num_objective_values
v = (Datum * sz)()
res = ccs_features_evaluation_get_objective_values(self.handle, sz, v, None)
Error.check(res)
self._objective_values = tuple(x.value for x in v)
return self._objective_values

def compare(self, other):
v = Comparison(0)
res = ccs_features_evaluation_compare(self.handle, other.handle, ct.byref(v))
Error.check(res)
return v.value

def check(self):
valid = ccs_bool()
res = res = ccs_features_evaluation(self.handle, ct.byref(valid))
Error.check(res)
return False if valid.value == 0 else True
67 changes: 3 additions & 64 deletions bindings/python/cconfigspace/tree_evaluation.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import ctypes as ct
from .base import Object, Error, CEnumeration, Result, ccs_evaluation_result, _ccs_get_function, ccs_context, ccs_parameter, ccs_tree_configuration, Datum, DatumFix, ccs_objective_space, ccs_tree_evaluation, ccs_bool
from .evaluation import Comparison
from .binding import Binding
from .base import Error, Datum, Result, _ccs_get_function, ccs_tree_configuration, ccs_tree_evaluation, ccs_objective_space, ccs_evaluation_result
from .evaluation_binding import EvaluationBinding
from .tree_configuration import TreeConfiguration
from .objective_space import ObjectiveSpace

ccs_create_tree_evaluation = _ccs_get_function("ccs_create_tree_evaluation", [ccs_objective_space, ccs_tree_configuration, ccs_evaluation_result, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ccs_tree_evaluation)])
ccs_tree_evaluation_get_objective_space = _ccs_get_function("ccs_tree_evaluation_get_objective_space", [ccs_tree_evaluation, ct.POINTER(ccs_objective_space)])
ccs_tree_evaluation_get_configuration = _ccs_get_function("ccs_tree_evaluation_get_configuration", [ccs_tree_evaluation, ct.POINTER(ccs_tree_configuration)])
ccs_tree_evaluation_get_result = _ccs_get_function("ccs_tree_evaluation_get_result", [ccs_tree_evaluation, ct.POINTER(ccs_evaluation_result)])
ccs_tree_evaluation_get_objective_value = _ccs_get_function("ccs_tree_evaluation_get_objective_value", [ccs_tree_evaluation, ct.c_size_t, ct.POINTER(Datum)])
ccs_tree_evaluation_get_objective_values = _ccs_get_function("ccs_tree_evaluation_get_objective_values", [ccs_tree_evaluation, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ct.c_size_t)])
ccs_tree_evaluation_compare = _ccs_get_function("ccs_tree_evaluation_compare", [ccs_tree_evaluation, ccs_tree_evaluation, ct.POINTER(Comparison)])
ccs_tree_evaluation_check = _ccs_get_function("ccs_tree_evaluation_check", [ccs_tree_evaluation, ct.POINTER(ccs_bool)])

class TreeEvaluation(Binding):
class TreeEvaluation(EvaluationBinding):
def __init__(self, handle = None, retain = False, auto_release = True,
objective_space = None, configuration = None, result = Result.SUCCESS, values = None):
if handle is None:
Expand All @@ -38,16 +30,6 @@ def __init__(self, handle = None, retain = False, auto_release = True,
def from_handle(cls, handle, retain = True, auto_release = True):
return cls(handle = handle, retain = retain, auto_release = auto_release)

@property
def objective_space(self):
if hasattr(self, "_objective_space"):
return self._objective_space
v = ccs_objective_space()
res = ccs_tree_evaluation_get_objective_space(self.handle, ct.byref(v))
Error.check(res)
self._objective_space = ObjectiveSpace.from_handle(v)
return self._objective_space

@property
def configuration(self):
if hasattr(self, "_configuration"):
Expand All @@ -57,46 +39,3 @@ def configuration(self):
Error.check(res)
self._configuration = TreeConfiguration.from_handle(v)
return self._configuration

@property
def result(self):
if hasattr(self, "_result"):
return self._result
v = ccs_evaluation_result()
res = ccs_tree_evaluation_get_result(self.handle, ct.byref(v))
Error.check(res)
self._result = v.value
return self._result

@property
def num_objective_values(self):
if hasattr(self, "_num_objective_values"):
return self._num_objective_values
v = ct.c_size_t()
res = ccs_tree_evaluation_get_objective_values(self.handle, 0, None, ct.byref(v))
Error.check(res)
self._num_objective_values = v.value
return self._num_objective_values

@property
def objective_values(self):
if hasattr(self, "_objective_values"):
return self._objective_values
sz = self.num_objective_values
v = (Datum * sz)()
res = ccs_tree_evaluation_get_objective_values(self.handle, sz, v, None)
Error.check(res)
self._objective_values = tuple(x.value for x in v)
return self._objective_values

def compare(self, other):
v = Comparison(0)
res = ccs_tree_evaluation_compare(self.handle, other.handle, ct.byref(v))
Error.check(res)
return v.value

def check(self):
valid = ccs_bool()
res = ccs_tree_evaluation_check(self.handle, ct.byref(valid))
Error.check(res)
return False if valid.value == 0 else True
1 change: 1 addition & 0 deletions bindings/ruby/lib/cconfigspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require_relative 'cconfigspace/features_space'
require_relative 'cconfigspace/features'
require_relative 'cconfigspace/objective_space'
require_relative 'cconfigspace/evaluation_binding'
require_relative 'cconfigspace/evaluation'
require_relative 'cconfigspace/features_evaluation'
require_relative 'cconfigspace/tuner'
Expand Down
2 changes: 2 additions & 0 deletions bindings/ruby/lib/cconfigspace/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Version < FFI::Struct
typedef :ccs_object_t, :ccs_features_space_t
typedef :ccs_object_t, :ccs_features_t
typedef :ccs_object_t, :ccs_objective_space_t
typedef :ccs_object_t, :ccs_evaluation_binding_t
typedef :ccs_object_t, :ccs_evaluation_t
typedef :ccs_object_t, :ccs_features_evaluation_t
typedef :ccs_object_t, :ccs_tuner_t
Expand All @@ -128,6 +129,7 @@ class MemoryPointer
alias read_ccs_features_space_t read_ccs_object_t
alias read_ccs_features_t read_ccs_object_t
alias read_ccs_objective_space_t read_ccs_object_t
alias read_ccs_evaluation_binding_t read_ccs_object_t
alias read_ccs_evaluation_t read_ccs_object_t
alias read_ccs_features_evaluation_t read_ccs_object_t
alias read_ccs_tuner_t read_ccs_object_t
Expand Down
Loading

0 comments on commit 1c501b0

Please sign in to comment.