Skip to content

Commit

Permalink
compare results
Browse files Browse the repository at this point in the history
  • Loading branch information
Betristor committed Sep 26, 2023
1 parent 32cebae commit b473e63
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 22 deletions.
2 changes: 2 additions & 0 deletions Example_Systems/SmallNewEngland/OneZone/Run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ outpath_GenX = write_outputs(EP, outpath, mysetup, myinputs)
if mysetup["ModelH2"] == 1
write_HSC_outputs(EP, outpath_GenX, mysetup, myinputs)
end

compare_results(outpath_GenX, joinpath(case_dir, "Results"))
2 changes: 2 additions & 0 deletions Example_Systems/SmallNewEngland/ThreeZones/Run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ outpath_GenX = write_outputs(EP, outpath, mysetup, myinputs)
if mysetup["ModelH2"] == 1
write_HSC_outputs(EP, outpath_GenX, mysetup, myinputs)
end

compare_results(outpath_GenX, joinpath(case_dir, "Results"))
14 changes: 7 additions & 7 deletions src/configure_solver/configure_highs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The HiGHS optimizer instance is configured with the following default parameters
TimeLimit: Inf # Time limit # [type: double, advanced: false, range: [0, inf], default: inf]
Pre_Solve: choose # Presolve option: "off", "choose" or "on" # [type: string, advanced: false, default: "choose"]
Method: ipm #choose #HiGHS-specific solver settings # Solver option: "simplex", "choose" or "ipm" # [type: string, advanced: false, default: "choose"] In order to run a case when the UCommit is set to 1, i.e. MILP instance, set the Method to choose
# HiGHS-specific solver settings
# Presolve option: "off", "choose" or "on"
# [type: string, advanced: false, default: "choose"]
Expand Down Expand Up @@ -447,7 +447,7 @@ function configure_highs(solver_settings_path::String)
if (haskey(solver_settings, "parallel"))
Myparallel = solver_settings["parallel"]
end
Myrun_crossover = false
Myrun_crossover = "off"
if (haskey(solver_settings, "run_crossover"))
Myrun_crossover = solver_settings["run_crossover"]
end
Expand Down Expand Up @@ -708,10 +708,10 @@ function configure_highs(solver_settings_path::String)
if (haskey(solver_settings, "allowed_cost_scale_factor"))
Myallowed_cost_scale_factor = solver_settings["allowed_cost_scale_factor"]
end
Mysimplex_dualise_strategy = -1
if (haskey(solver_settings, "simplex_dualise_strategy"))
Mysimplex_dualise_strategy = solver_settings["simplex_dualise_strategy"]
end
# Mysimplex_dualise_strategy = -1
# if (haskey(solver_settings, "simplex_dualise_strategy"))
# Mysimplex_dualise_strategy = solver_settings["simplex_dualise_strategy"]
# end
Mysimplex_permute_strategy = -1
if (haskey(solver_settings, "simplex_permute_strategy"))
Mysimplex_permute_strategy = solver_settings["simplex_permute_strategy"]
Expand Down Expand Up @@ -897,7 +897,7 @@ function configure_highs(solver_settings_path::String)
"cost_scale_factor" => Mycost_scale_factor,
"allowed_matrix_scale_factor" => Myallowed_matrix_scale_factor,
"allowed_cost_scale_factor" => Myallowed_cost_scale_factor,
"simplex_dualise_strategy" => Mysimplex_dualise_strategy,
# "simplex_dualise_strategy" => Mysimplex_dualise_strategy,
"simplex_permute_strategy" => Mysimplex_permute_strategy,
"max_dual_simplex_cleanup_level" => Mymax_dual_simplex_cleanup_level,
"max_dual_simplex_phase1_cleanup_level" =>
Expand Down
70 changes: 55 additions & 15 deletions src/core/compare_results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,38 @@ received this license file. If not, see <http://www.gnu.org/licenses/>.
This function compares the contents of two directories and returns a summary file of the differences
"""
function compare_results(path1::AbstractString, path2::AbstractString, output_filename::AbstractString="summary.txt")
lines_to_write = compare_dir(path1, path2)
print_comparison(lines_to_write, output_filename)
function compare_results(
path1::AbstractString,
path2::AbstractString,
output_filename::AbstractString = "summary.txt",
)
## Check that the paths are valid
if !isdir(path1) || !isdir(path2) || path1 == path2
println("One or Both of the Paths Doesn't Exist or They are the Same")
else
lines_to_write, identical_structure, identical_contents = compare_dir(path1, path2)
if identical_structure
println("Structure of $path1 and $path2 is Identical")
end
if identical_contents
println("Contents of $path1 and $path2 is Identical")
end
if !identical_structure || !identical_contents
print_comparison(lines_to_write, output_filename)
end
end
end

@doc raw"""
print_comparison(path1::AbstractString, path2::AbstractString, output_filename::AbstractString="summary.txt")
Takes a string array of differences between two directories and prints them to a file
"""
function print_comparison(lines_to_write::Array{Any,1}, output_filename::AbstractString="summary.txt")
summary_file = open(output_filename, "w")
function print_comparison(
lines_to_write::Array{Any,1},
output_filename::AbstractString = "summary.txt",
)
summary_file = open(output_filename, "a")
write(summary_file, join(lines_to_write))
close(summary_file)
end
Expand All @@ -40,13 +60,17 @@ end
Compares the contents of two directories and returns a string array of the differences
"""
function compare_dir(path1::AbstractString, path2::AbstractString, inset::String="")
function compare_dir(path1::AbstractString, path2::AbstractString, inset::String = "")
# Get the list of files in each directory
files1 = readdir(path1)
files2 = readdir(path2)
files1 = filter(x -> !any(occursin.(["log", "lp", "txt"], x)), readdir(path1))
files2 = filter(x -> !any(occursin.(["log", "lp", "txt"], x)), readdir(path2))
dirname1 = split(path1, "\\")[end]
dirname2 = split(path2, "\\")[end]

## Flag denoting whether the structure and contents are identical
identical_structure = true
identical_contents = true

# Get the list of files that are in both directories
common_files = intersect(files1, files2)

Expand All @@ -55,7 +79,7 @@ function compare_dir(path1::AbstractString, path2::AbstractString, inset::String
only2 = setdiff(files2, common_files)

# Create a summary file

lines_to_write = []
push!(lines_to_write, "$(inset)Comparing the following directories:\n")
push!(lines_to_write, "$(inset)--- $dirname1 ---\n")
Expand All @@ -67,17 +91,22 @@ function compare_dir(path1::AbstractString, path2::AbstractString, inset::String
push!(lines_to_write, "$(inset)Files in $dirname1 but not in $dirname2:\n")
push!(lines_to_write, join([inset, join(only1, "\n$inset")]))
push!(lines_to_write, "\n")
identical_structure = false
end
if length(only2) > 0
push!(lines_to_write, "$(inset)Files in $dirname2 but not in $dirname1:\n")
push!(lines_to_write, join([inset, join(only2, "\n$inset")]))
push!(lines_to_write, "\n")
identical_structure = false
end
if length(only1) == 0 && length(only2) ==0
push!(lines_to_write, "$(inset)Both directories contain the same files and subdirectories\n")
if length(only1) == 0 && length(only2) == 0
push!(
lines_to_write,
"$(inset)Both directories contain the same files and subdirectories\n",
)
end
push!(lines_to_write, "\n")

common_files_matching = []
common_files_diff = []
subdirs = []
Expand Down Expand Up @@ -108,6 +137,7 @@ function compare_dir(path1::AbstractString, path2::AbstractString, inset::String
if length(common_files_diff) > 0
push!(lines_to_write, join([inset, "Mismatched result files: \n"]))
push!(lines_to_write, join([inset, join(common_files_diff, "\n$inset")]))
identical_contents = false
else
push!(lines_to_write, join([inset, "No mismatched result files"]))
end
Expand All @@ -118,13 +148,23 @@ function compare_dir(path1::AbstractString, path2::AbstractString, inset::String
push!(lines_to_write, join([inset, "Sub-directories"]))
push!(lines_to_write, "\n")
for subdir in subdirs
lines_to_write = [lines_to_write; compare_dir(joinpath(path1, subdir), joinpath(path2, subdir), join([inset, " "]))]
lines_to_write = [
lines_to_write
first(
compare_dir(
joinpath(path1, subdir),
joinpath(path2, subdir),
join([inset, " "]),
),
)
]
end
push!(lines_to_write, "\n")
end
end
return lines_to_write
return lines_to_write, identical_structure, identical_contents
end

@doc raw"""
filecmp_byte(path1::AbstractString, path2::AbstractString)
Expand Down

0 comments on commit b473e63

Please sign in to comment.