2023-11-13 12:55:02 +01:00
|
|
|
"""
|
|
|
|
GreedyOptimizer
|
|
|
|
|
|
|
|
An implementation of the greedy optimization algorithm, simply choosing the best next option evaluated with the given estimator.
|
|
|
|
"""
|
2023-11-20 19:07:05 +01:00
|
|
|
struct GreedyOptimizer{EstimatorType <: AbstractEstimator} <: AbstractOptimizer
|
|
|
|
estimator::EstimatorType
|
|
|
|
end
|
|
|
|
|
|
|
|
function optimize_step!(optimizer::GreedyOptimizer, graph::DAG)
|
|
|
|
# generate all options
|
|
|
|
operations = get_operations(graph)
|
|
|
|
if isempty(operations)
|
|
|
|
println("[warn] No operations left to apply")
|
|
|
|
return nothing
|
|
|
|
end
|
|
|
|
|
|
|
|
lowestCost = typemax(cost_type(optimizer.estimator))
|
|
|
|
|
|
|
|
result = reduce((acc, op) -> begin
|
|
|
|
op_cost = operation_effect(optimizer.estimator, graph, op)
|
|
|
|
if op_cost < lowestCost
|
|
|
|
lowestCost = op_cost
|
|
|
|
return op
|
|
|
|
end
|
|
|
|
return acc
|
|
|
|
end, operations)
|
|
|
|
|
|
|
|
push_operation!(graph, result)
|
|
|
|
|
|
|
|
return nothing
|
2023-11-13 12:55:02 +01:00
|
|
|
end
|