Skip to content

Commit ff7131f

Browse files
authored
Feature table logger (#277)
* use TableLogger.jl * removed previous tablelogger * Only Julia v1.6 and v0.1 of TableLogger not double CI
1 parent b9b2aa8 commit ff7131f

File tree

9 files changed

+34
-384
lines changed

9 files changed

+34
-384
lines changed

.github/workflows/ci.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
name: CI
22
on:
3-
- push
4-
- pull_request
3+
push:
4+
branches:
5+
- master
6+
tags: '*'
7+
pull_request:
58
jobs:
69
test:
710
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
@@ -10,7 +13,7 @@ jobs:
1013
fail-fast: false
1114
matrix:
1215
version:
13-
- '1.2'
16+
- '1.6'
1417
- '1'
1518
os:
1619
- ubuntu-latest

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# ConstrainSolver.jl - Changelog
22

3+
## v0.8.0 (not yet released)
4+
- Using [TableLogger.jl](https://github.com/Wikunia/TableLogger.jl)
5+
- Only support Julia v1.6 and above
36
## v0.7.1 (1st of November 2021)
47
- Using priority queue also for `BFS` problems [PR #274](https://github.com/Wikunia/ConstraintSolver.jl/pull/274)
58

Project.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1616
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1717
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
1818
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
19+
TableLogger = "72b659bb-f61b-4d0d-9dbb-0f81f57d8545"
1920

2021
[compat]
2122
ConstraintProgrammingExtensions = "^0.3"
@@ -28,4 +29,5 @@ MathOptInterface = "^0.9.11"
2829
MatrixNetworks = "^1"
2930
StatsBase = "^0.33"
3031
StatsFuns = "^0.9.5"
31-
julia = "^1.2"
32+
TableLogger = "^0.1"
33+
julia = "^1.6"

src/ConstraintSolver.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ using Random
2828
using Statistics
2929
using StatsBase
3030
using StatsFuns
31+
using TableLogger
3132

3233
const CPE = ConstraintProgrammingExtensions
3334

@@ -51,7 +52,6 @@ const VAR_TYPES = Union{MOI.ZeroOne,MOI.Integer}
5152
include("types.jl")
5253
const CoM = ConstraintSolverModel
5354

54-
include("tablelogger.jl")
5555
include("options.jl")
5656

5757

@@ -409,7 +409,7 @@ function add_new_solution!(
409409
new_sol_obj = Solution(new_sol, CS.value.(com.search_space), backtrack_obj.idx)
410410
push!(com.solutions, new_sol_obj)
411411
com.best_sol = new_sol
412-
log_table && (last_table_row = update_table_log(com, backtrack_vec; force = true))
412+
log_table && update_table_log(com, backtrack_vec)
413413
if com.best_sol == com.best_bound && !find_more_solutions
414414
return true
415415
end
@@ -429,7 +429,7 @@ function add_new_solution!(
429429
end
430430
end
431431
else # if new solution was found but it's worse
432-
log_table && (last_table_row = update_table_log(com, backtrack_vec; force = true))
432+
log_table && update_table_log(com, backtrack_vec)
433433
if com.options.all_solutions
434434
new_sol_obj = Solution(new_sol, CS.value.(com.search_space), backtrack_obj.idx)
435435
push!(com.solutions, new_sol_obj)
@@ -547,7 +547,7 @@ function backtrack!(
547547

548548
find_more_solutions = com.options.all_solutions || com.options.all_optimal_solutions
549549

550-
log_table && println(get_header(com.options.table))
550+
log_table && print_header(com.options.table)
551551

552552
backtrack_vec = com.backtrack_vec
553553

@@ -626,7 +626,7 @@ function backtrack!(
626626
cb_finished_pruning(com)
627627

628628
if log_table
629-
last_table_row = update_table_log(com, backtrack_vec)
629+
update_table_log(com, backtrack_vec)
630630
end
631631

632632
branch_var = get_next_branch_variable(com)

src/options.jl

+8-9
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ const POSSIBLE_OPTIONS = Dict(
3131

3232
function SolverOptions()
3333
logging = [:Info, :Table]
34-
table = TableSetup(
35-
[
36-
CS.TableCol(:open_nodes, "#Open", Int, 10, :center),
37-
CS.TableCol(:closed_nodes, "#Closed", Int, 10, :center),
38-
CS.TableCol(:incumbent, "Incumbent", Float64, 20, :center),
39-
CS.TableCol(:best_bound, "Best Bound", Float64, 20, :center),
40-
CS.TableCol(:duration, "Time [s]", Float64, 10, :center),
41-
],
42-
Dict(:min_diff_duration => 5.0),
34+
35+
table = init_log_table(
36+
(id=:open_nodes, name="#Open", width=10),
37+
(id=:closed_nodes, name="#Closed", width=10),
38+
(id=:incumbent, name="Incumbent", width=20),
39+
(id=:best_bound, name="Best Bound", width=20),
40+
(id=:duration, name="Time [s]", width=10);
41+
alignment=:center
4342
)
4443
seed = 1
4544
traverse_strategy = :Auto

src/tablelogger.jl

-198
This file was deleted.

src/types.jl

+1-25
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
# TableLogger
2-
3-
mutable struct TableCol
4-
id::Symbol
5-
name::String
6-
type::DataType
7-
width::Int
8-
alignment::Symbol # :left, :center, :right
9-
b_format::Bool
10-
end
11-
12-
mutable struct TableEntry{T}
13-
col_id::Symbol
14-
value::T
15-
end
16-
17-
mutable struct TableSetup
18-
cols::Vector{TableCol}
19-
col_idx::Dict{Symbol,Int}
20-
new_row_criteria::Bool
21-
diff_criteria::Dict{Symbol,Any}
22-
last_row::Vector{TableEntry}
23-
end
24-
251
# SolverOptions
262
mutable struct ActivityOptions
273
decay::Float64
@@ -31,7 +7,7 @@ end
317

328
mutable struct SolverOptions
339
logging::Vector{Symbol}
34-
table::TableSetup
10+
table::TableLogger.Table
3511
time_limit::Float64 # time limit in backtracking in seconds
3612
seed::Int
3713
traverse_strategy::Symbol

src/util.jl

+8-10
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,21 @@ end
7070
7171
Push the new information to the TableLogger and if `force` produce a new line otherwise the TableLogger decides
7272
"""
73-
function update_table_log(com::CS.CoM, backtrack_vec; force = false)
73+
function update_table_log(com::CS.CoM, backtrack_vec)
7474
table = com.options.table
7575
open_nodes = count(n -> n.status == :Open, backtrack_vec)
7676
# -1 for dummy node
7777
closed_nodes = length(backtrack_vec) - open_nodes - 1
7878
best_bound = com.best_bound
7979
incumbent = length(com.solutions) == 0 ? "-" : com.best_sol
8080
duration = time() - com.start_time
81-
push_to_table!(
82-
table;
83-
force = force,
84-
open_nodes = open_nodes,
85-
closed_nodes = closed_nodes,
86-
incumbent = incumbent,
87-
best_bound = best_bound,
88-
duration = duration,
89-
)
81+
82+
set_value!(table, :open_nodes, Diff10(open_nodes))
83+
set_value!(table, :closed_nodes, Diff10(closed_nodes))
84+
set_value!(table, :incumbent, incumbent)
85+
set_value!(table, :best_bound, best_bound)
86+
set_value!(table, :duration, Diff5(duration))
87+
print_line(table; force=false)
9088
end
9189

9290
"""

0 commit comments

Comments
 (0)