Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new search strategy: Large Neighborhood Search (LNS) #204

Merged
merged 23 commits into from
Mar 31, 2022

Conversation

marco-novaes98
Copy link
Contributor

Implementation of Large Neighborhood Search (LNS) to add a new search strategy to SeaPearl (existing strategies: DFS, IDS and RBS)

@marco-novaes98 marco-novaes98 marked this pull request as draft February 25, 2022 21:29
@marco-novaes98 marco-novaes98 requested a review from 3rdCore March 7, 2022 17:50
@marco-novaes98 marco-novaes98 marked this pull request as ready for review March 7, 2022 20:08
@marco-novaes98 marco-novaes98 changed the title Marco/lns Add new search strategy: Large Neighborhood Search (LNS) Mar 16, 2022

"""
struct LNSearch <: SearchStrategy
implements the basic version of the Large Neighboorhood Search.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add a bit more doc about the Large Neighboorhood search or provide an external link

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


### Destroy and repair loop ###

while (isnothing(globalTimeLimit) || peektimer() < globalTimeLimit) && bestSolution[objective] > optimalScore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optimalScore can be deceiving. I 'd rather use optimalScoreLowerBound

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Comment on lines 138 to 161
function destroy(model, solution, numberOfValuesToRemove, objective)

# Reset model
objectiveBound = solution[objective] - 1
SeaPearl.reset_model!(model)

# Get variable fixed by current solution
vars = collect(values(model.variables))
branchableVariablesId = collect(filter(e -> model.branchable[e], keys(model.branchable)))
varsToSet = sample(branchableVariablesId, count(values(model.branchable)) - numberOfValuesToRemove; replace=false)

# Fix some variables as in current solution
for var in varsToSet
variable = vars[findfirst(e -> e.id == var, vars)]
value = solution[var]
SeaPearl.assign!(variable, value)
end

# Pruning the objective domain to force the search for a better solution
objectiveVariable = vars[findfirst(e -> e.id == objective, vars)]
SeaPearl.removeAbove!(objectiveVariable.domain, objectiveBound)

return model
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some testsets on destroy function would be usefull

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

# Get variable fixed by current solution
vars = collect(values(model.variables))
branchableVariablesId = collect(filter(e -> model.branchable[e], keys(model.branchable)))
varsToSet = sample(branchableVariablesId, count(values(model.branchable)) - numberOfValuesToRemove; replace=false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add seed on the LNSearch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I tried to add tests for the seedargument but I think there is no way to do it... But I have tested locally and it works properly!

Comment on lines 121 to 133
function repair(model, repairSearch, objective, variableHeuristic, valueSelection)
search!(model, repairSearch, variableHeuristic, valueSelection)
solutions = filter(e -> !isnothing(e), model.statistics.solutions)

if isempty(solutions)
toReturn = nothing
else
scores = map(solution -> solution[objective], solutions)
bestSolution = solutions[findfirst(score -> score == Base.minimum(scores), scores)]
toReturn = bestSolution
end
return toReturn
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some testsets on repair function would be usefull

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Collaborator

@3rdCore 3rdCore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice testsets, you clearly understood the underlying benefit of having diverse unit tests !

We just need to fix the little bug regarding the package CircularArrayBuffer.jl and you can merge the PR !


search = SeaPearl.LNSearch(limitValuesToRemove = 1)
status = SeaPearl.expandLns!(search, model, SeaPearl.MinDomainVariableSelection(), SeaPearl.BasicHeuristic())
@test status === :NonOptimal
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you recall why the result is not Optimal ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the first solution found (during initialization) will be {x => 2, y => 2} (because BasicHeuristic choose the biggest value in the domain). This solution is non optimal as x is the objective variable and his domain is {1, 2}. As we set limitValuesToRemove to 1, the destroy and repair loop will never reach any solution (because of the constraint Equal(x, y, trailer)). In that way, the solution returned will be {x => 2, y => 2} (≠ to optimal solution {x => 1, y => 1}).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add some comments in test file

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks, that's perfectly clear!

@3rdCore
Copy link
Collaborator

3rdCore commented Mar 17, 2022

Last query : could you update some functions documentation to satisfy the standard function head where the arguments are individually listed and explained?

@3rdCore
Copy link
Collaborator

3rdCore commented Mar 18, 2022

Everything looks good for me ! You can squash & merge the PR !

@marco-novaes98 marco-novaes98 merged commit 34262ef into master Mar 31, 2022
@marco-novaes98 marco-novaes98 deleted the marco/LNS branch March 31, 2022 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants