Skip to content

Commit

Permalink
Remove Heuristic module (#1120)
Browse files Browse the repository at this point in the history
  • Loading branch information
rrsadykov authored Jan 19, 2024
1 parent 223a72d commit bc20f1f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/Algorithm/Algorithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using DataStructures
import MathOptInterface
import TimerOutputs

using ..Coluna, ..ColunaBase, ..MathProg, ..MustImplement, ..ColGen, ..Benders, ..AlgoAPI, ..TreeSearch, ..Branching, ..Heuristic
using ..Coluna, ..ColunaBase, ..MathProg, ..MustImplement, ..ColGen, ..Benders, ..AlgoAPI, ..TreeSearch, ..Branching

using Crayons, DynamicSparseArrays, Logging, Parameters, Printf, Random, Statistics, SparseArrays, LinearAlgebra

Expand Down
18 changes: 12 additions & 6 deletions src/Algorithm/conquer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# ParameterizedHeuristic
####################################################################

struct ParameterizedHeuristic{A <: AlgoAPI.AbstractAlgorithm}
struct ParameterizedHeuristic{A <: AbstractOptimizationAlgorithm}
algorithm::A
root_priority::Float64
nonroot_priority::Float64
Expand Down Expand Up @@ -261,14 +261,20 @@ function run_heuristics!(ctx::ColCutGenContext, heuristics, env, reform, input,
records = create_records(reform)
end

output = Heuristic.run(heuristic.algorithm, env, reform, conquer_output)
for sol in Heuristic.get_primal_sols(output)
store_ip_primal_sol!(get_global_primal_handler(input), sol)
end

heuristic_output = run!(heuristic.algorithm, env, reform, conquer_output)
update!(conquer_output, heuristic_output)
# for sol in Heuristic.get_primal_sols(output)
# store_ip_primal_sol!(get_global_primal_handler(input), sol)
# end

if ismanager(heuristic.algorithm)
restore_from_records!(input.units_to_restore, records)
end

if getterminationstatus(conquer_output) == TIME_LIMIT ||
ip_gap_closed(conquer_output, atol = ctx.params.opt_atol, rtol = ctx.params.opt_rtol)
return false
end
end
return true
end
Expand Down
24 changes: 13 additions & 11 deletions src/Algorithm/heuristic/restricted_master.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ optimizes the master problem restricted to active master column variables using
If the heuristic finds a solution, it checks that this solution does not violate any essential
cut.
"""
struct RestrictedMasterHeuristic <: Heuristic.AbstractHeuristic
struct RestrictedMasterHeuristic <: AbstractOptimizationAlgorithm
solve_ip_form_alg::SolveIpForm

RestrictedMasterHeuristic(;
Expand All @@ -21,27 +21,29 @@ function get_child_algorithms(algo::RestrictedMasterHeuristic, reform::Reformula
return child_algs
end

struct RestrictedMasterHeuristicOutput <: Heuristic.AbstractHeuristicOutput
ip_primal_sols::Vector{PrimalSolution}
end
# struct RestrictedMasterHeuristicOutput <: Heuristic.AbstractHeuristicOutput
# ip_primal_sols::Vector{PrimalSolution}
# end

Heuristic.get_primal_sols(o::RestrictedMasterHeuristicOutput) = o.ip_primal_sols
# Heuristic.get_primal_sols(o::RestrictedMasterHeuristicOutput) = o.ip_primal_sols

function Heuristic.run(algo::RestrictedMasterHeuristic, env, reform, opt_state::OptimizationState)
ip_form_output = run!(algo.solve_ip_form_alg, env, getmaster(reform), opt_state)
function run!(algo::RestrictedMasterHeuristic, env, reform, input::OptimizationState)
master = getmaster(reform)
ip_form_output = run!(algo.solve_ip_form_alg, env, master, input)
ip_primal_sols = get_ip_primal_sols(ip_form_output)

output = OptimizationState(master)

# We need to make sure that the solution is feasible by separating essential cuts and then
# project the solution on master.
feasible_ip_primal_sols = PrimalSolution[]
if length(ip_primal_sols) > 0
for sol in sort(ip_primal_sols) # we start with worst solution to add all improving solutions
cutgen = CutCallbacks(call_robust_facultative = false)
cutcb_output = run!(cutgen, env, getmaster(reform), CutCallbacksInput(sol))
cutcb_output = run!(cutgen, env, master, CutCallbacksInput(sol))
if cutcb_output.nb_cuts_added == 0
push!(feasible_ip_primal_sols, sol)
add_ip_primal_sol!(output, sol)
end
end
end
return RestrictedMasterHeuristicOutput(feasible_ip_primal_sols)
return output
end
3 changes: 0 additions & 3 deletions src/Coluna.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ using .ColGen
include("Benders/Benders.jl")
using .Benders

include("Heuristic/Heuristic.jl")
using .Heuristic

include("Algorithm/Algorithm.jl")
using .Algorithm

Expand Down
29 changes: 0 additions & 29 deletions src/Heuristic/Heuristic.jl

This file was deleted.

0 comments on commit bc20f1f

Please sign in to comment.