Skip to content

Commit

Permalink
Fix arg order in Fluct
Browse files Browse the repository at this point in the history
  • Loading branch information
Azzaare committed Jun 11, 2021
1 parent 3acb306 commit 1c9ae49
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/fluct.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
struct Fluct
cons::Dictionary{Int, Float64}
vars::Dictionary{Int, Float64}
Fluct(cons, vars) = new(zeros(cons), zeros(vars))
end

Fluct(cons, vars) = Fluct(zeros(cons), zeros(vars))


function reset!(fluct)
zeros! = d -> foreach(k -> set!(d, k, 0.0), keys(d))
Expand All @@ -12,11 +13,11 @@ function reset!(fluct)
end

function copy_to!(fluct, cons, vars)
foreach(k -> set!(fluct.cons, k, cons[k]), cons)
foreach(k -> set!(fluct.vars, k, vars[k]), vars)
foreach(k -> set!(fluct.cons, k, cons[k]), keys(cons))
foreach(k -> set!(fluct.vars, k, vars[k]), keys(vars))
end

function copy_from!(fluct, cons, vars)
foreach(k -> set!(cons, k, fluct.cons[k]), cons)
foreach(k -> set!(vars, k, fluct.vars[k]), vars)
end
foreach(k -> set!(cons, k, fluct.cons[k]), keys(cons))
foreach(k -> set!(vars, k, fluct.vars[k]), keys(vars))
end
4 changes: 2 additions & 2 deletions src/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ function _move!(s, x::Int, dim::Int=0)
best_values = [begin old_v = _value(s, x) end]; best_swap = [x]
tabu = true # unless proved otherwise, this variable is now tabu
best_cost = old_cost = get_error(s)
copy_to!(s.state.fluct, _vars_costs(s), _cons_costs(s))
copy_to!(s.state.fluct, _cons_costs(s), _vars_costs(s))
for v in _neighbours(s, x, dim)
dim == 0 && v == old_v && continue
dim == 0 ? _value!(s, x, v) : _swap_value!(s, x, v)
Expand All @@ -315,7 +315,7 @@ function _move!(s, x::Int, dim::Int=0)
return best_values, best_swap, tabu
end

copy_from!(s.state.fluct, _vars_costs(s), _cons_costs(s))
copy_from!(s.state.fluct, _cons_costs(s), _vars_costs(s))
set_error!(s, old_cost)

# swap/change back the value of x (and y/)
Expand Down

0 comments on commit 1c9ae49

Please sign in to comment.