-
Notifications
You must be signed in to change notification settings - Fork 3
add node directly with default empty BnBNodeInfo #38
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,38 +25,37 @@ Bonobo.set_root!(tree, ( | |
| )) | ||
| ``` | ||
| """ | ||
| function set_root!(tree::BnBTree, node_info::NamedTuple) | ||
| add_node!(tree, nothing, node_info) | ||
| function set_root!(tree::BnBTree, node::AbstractNode) | ||
| add_node!(tree, nothing, node) | ||
| end | ||
|
|
||
| """ | ||
| add_node!(tree::BnBTree{Node}, parent::Union{AbstractNode, Nothing}, node_info::NamedTuple) | ||
| add_node!(tree::BnBTree{Node}, parent::Union{Node, Nothing}, node::Node) where Node <: AbstractNode | ||
|
|
||
| Add a new node to the tree using the `node_info`. For information on that see [`set_root!`](@ref). | ||
| Add a new node to the tree using the `node`. For information on that see [`set_root!`](@ref). | ||
| """ | ||
| function add_node!(tree::BnBTree{Node}, parent::Union{AbstractNode, Nothing}, node_info::NamedTuple) where Node <: AbstractNode | ||
| function add_node!(tree::BnBTree{Node}, parent::Union{Node, Nothing}, node::Node) where Node <: AbstractNode | ||
| node_id = tree.num_nodes + 1 | ||
| node = create_node(Node, node_id, parent, node_info) | ||
| node = create_node(Node, node_id, parent, node) | ||
| tree.nodes[node_id] = node | ||
| tree.node_queue[node_id] = (node.lb, node_id) | ||
| tree.num_nodes += 1 | ||
| end | ||
|
|
||
| """ | ||
| create_node(Node, node_id::Int, parent::Union{AbstractNode, Nothing}, node_info::NamedTuple) | ||
| create_node(Node, node_id::Int, parent::Union{AbstractNode, Nothing}, node::AbstractNode) | ||
|
|
||
| Creates a node of type `Node` with id `node_id` and the named tuple `node_info`. | ||
| Creates a node of type `Node` with id `node_id` and the named tuple `node`. | ||
| For information on that see [`set_root!`](@ref). | ||
| """ | ||
| function create_node(Node, node_id::Int, parent::Union{AbstractNode, Nothing}, node_info::NamedTuple) | ||
| function create_node(Node, node_id::Int, parent::Union{AbstractNode, Nothing}, node::AbstractNode) | ||
|
Comment on lines
+48
to
+51
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is strange here, we have a function create node that already takes as input the created node?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that's the reason why I don't like this approach same with the mutable but I wasn't able to come up with something better which is most likely the reason why I used the named tuple approach 🤣 |
||
| lb = -Inf | ||
| if !isnothing(parent) | ||
| lb = parent.lb | ||
| end | ||
| bnb_node = structfromnt(BnBNodeInfo, (id = node_id, lb = lb, ub = Inf)) | ||
| bnb_nt = (std = bnb_node,) | ||
| node_nt = merge(bnb_nt, node_info) | ||
| return structfromnt(Node, node_nt) | ||
| bnb_node = BnBNodeInfo(node_id, lb, Inf) | ||
| node.std = bnb_node | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the default here assumes the node is mutable? |
||
| return node | ||
| end | ||
|
|
||
| """ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.