f5
Co-authored-by: gdamms <gdamms@users.noreply.github.com>
This commit is contained in:
parent
576268b061
commit
055048dbae
1689
notebook.ipynb
1689
notebook.ipynb
File diff suppressed because one or more lines are too long
|
@ -1,18 +1,3 @@
|
||||||
import Pkg;
|
|
||||||
Pkg.add("GraphRecipes");
|
|
||||||
Pkg.add("Plots");
|
|
||||||
using GraphRecipes, Plots #only used to visualize the search tree at the end of the branch-and-bound
|
|
||||||
|
|
||||||
"""Open and read a KnapFile.
|
|
||||||
|
|
||||||
Args: \\
|
|
||||||
- filename (String): the name of the file to read.
|
|
||||||
|
|
||||||
Returns: \\
|
|
||||||
- price (Vector{Integer}): prices of items to put in the KnapSack. \\
|
|
||||||
- weight (Vector{Integer}): weights of items to put in the KnapSack. \\
|
|
||||||
- capacity (Integer): the maximum capacity of the KnapSack.
|
|
||||||
"""
|
|
||||||
function readKnapInstance(filename)
|
function readKnapInstance(filename)
|
||||||
price = []
|
price = []
|
||||||
weight = []
|
weight = []
|
||||||
|
@ -38,24 +23,6 @@ function readKnapInstance(filename)
|
||||||
return price, weight, capacity
|
return price, weight, capacity
|
||||||
end
|
end
|
||||||
|
|
||||||
"""Test if a node should be pruned.
|
|
||||||
|
|
||||||
Args: \\
|
|
||||||
- x (Vector{Integer}): the node to be tested. \\
|
|
||||||
- price (Vector{Integer}): prices of items to put in the KnapSack. \\
|
|
||||||
- weight (Vector{Integer}): weights of items to put in the KnapSack. \\
|
|
||||||
- capacity (Integer): the maximum capacity of the KnapSack. \\
|
|
||||||
- BestProfit (Integer): the current BestProfit value. \\
|
|
||||||
- Bestsol (Integer): the current BestSol values. \\
|
|
||||||
- affich (Bool): determine if the function should print to stdout.
|
|
||||||
|
|
||||||
Returns: \\
|
|
||||||
- TA (Bool): true if the node is feasible. \\
|
|
||||||
- TO (Bool): true if the node is optimal. \\
|
|
||||||
- TR (Bool): true if the node is resolvable. \\
|
|
||||||
- BestProfit (Integer): the updated value of BestProfit. \\
|
|
||||||
- Bestsol (Vector{Integer}): the updated values of BestSol.
|
|
||||||
"""
|
|
||||||
function TestsSondabilite_relaxlin(x, price, weight, capacity, BestProfit, Bestsol, affich)
|
function TestsSondabilite_relaxlin(x, price, weight, capacity, BestProfit, Bestsol, affich)
|
||||||
TA, TO, TR = false, false, false
|
TA, TO, TR = false, false, false
|
||||||
|
|
||||||
|
@ -96,17 +63,6 @@ function TestsSondabilite_relaxlin(x, price, weight, capacity, BestProfit, Bests
|
||||||
return TA, TO, TR, Bestsol, BestProfit
|
return TA, TO, TR, Bestsol, BestProfit
|
||||||
end
|
end
|
||||||
|
|
||||||
"""Split a node in two.
|
|
||||||
|
|
||||||
Args: \\
|
|
||||||
- price (Vector{Integer}): prices of items to put in the KnapSack. \\
|
|
||||||
- listvars (Vector{Vector{Integer}}): the current values of listvars. \\
|
|
||||||
- listvals (Vector{Integer}): the current values of listvals.
|
|
||||||
|
|
||||||
Returns: \\
|
|
||||||
- listvars (Vector{Vector{Integer}}): the updated values of listvars. \\
|
|
||||||
- listvals (Vector{Integer}): the updated values of listvals.
|
|
||||||
"""
|
|
||||||
function SeparerNoeud_relaxlin(price, listvars, listvals)
|
function SeparerNoeud_relaxlin(price, listvars, listvals)
|
||||||
# Le noeud est non-sondable. Appliquer le critère de séparation pour le séparer en sous-noeuds
|
# Le noeud est non-sondable. Appliquer le critère de séparation pour le séparer en sous-noeuds
|
||||||
|
|
||||||
|
@ -148,18 +104,6 @@ function SeparerNoeud_relaxlin(price, listvars, listvals)
|
||||||
return listvars, listvals
|
return listvars, listvals
|
||||||
end
|
end
|
||||||
|
|
||||||
"""Pop node fom the list to explore another node.
|
|
||||||
|
|
||||||
Args: \\
|
|
||||||
- price (Vector{Integer}): prices of items to put in the KnapSack. \\
|
|
||||||
- listvars (Vector{Vector{Integer}}): the current values of listvars. \\
|
|
||||||
- listvals (Vector{Integer}): the current values of listvals.
|
|
||||||
|
|
||||||
Returns: \\
|
|
||||||
- listvars (Vector{Vector{Integer}}): the updated values of listvars. \\
|
|
||||||
- listvals (Vector{Integer}): the updated values of listvals. \\
|
|
||||||
- stop (Bool): true if the tree search is finished.
|
|
||||||
"""
|
|
||||||
function ExplorerAutreNoeud_relaxlin(listvars, listvals)
|
function ExplorerAutreNoeud_relaxlin(listvars, listvals)
|
||||||
# Le noeud est sondable, on l'enlève de la pile des noeuds à sonder
|
# Le noeud est sondable, on l'enlève de la pile des noeuds à sonder
|
||||||
|
|
||||||
|
@ -208,16 +152,6 @@ function AllDef(x)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
"""Solve the KnapSack problem for the data contained in `filename`.
|
|
||||||
|
|
||||||
Args: \\
|
|
||||||
- filename (String): the name of the file to read.
|
|
||||||
|
|
||||||
Returns: \\
|
|
||||||
- trParentnodes (Vector{Integer}): the parents nodes, to plot the tree.
|
|
||||||
- trChildnodes (Vector{Integer}): the child nodes, to plot the tree.
|
|
||||||
- trNamenodes (Vector{Integer}): the name of the nodes, to plot the tree.
|
|
||||||
"""
|
|
||||||
function SolveKnapInstance(filename)
|
function SolveKnapInstance(filename)
|
||||||
|
|
||||||
stop = false
|
stop = false
|
||||||
|
@ -307,4 +241,3 @@ function SolveKnapInstance(filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
trParentnodes, trChildnodes, trNamenodes = SolveKnapInstance("data/circle/knapPI_16_10000_1000_5_-912198.opb")
|
trParentnodes, trChildnodes, trNamenodes = SolveKnapInstance("data/circle/knapPI_16_10000_1000_5_-912198.opb")
|
||||||
# graphplot(trParentnodes, trChildnodes, names = trNamenodes, method = :tree)
|
|
Loading…
Reference in a new issue