33 lines
878 B
Julia
Raw Normal View History

"""
GreedyOptimizer
An implementation of the greedy optimization algorithm, simply choosing the best next option evaluated with the given estimator.
"""
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
end