Skip to content

Commit 69e37c3

Browse files
committed
upd: added function to retrieve children of node
1 parent 9f547fb commit 69e37c3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/node.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::ffi;
22
use crate::scip::ScipPtr;
3+
use std::num;
34
use std::rc::Rc;
45

56
/// A node in the branch-and-bound tree.
@@ -42,6 +43,29 @@ impl Node {
4243
})
4344
}
4445
}
46+
47+
/// Returns the children of the node.
48+
pub fn children(&self) -> Option<Vec<Node>> {
49+
let num_children = unsafe { ffi::SCIPgetNChildren(self.scip.raw) };
50+
if num_children == 0 {
51+
return None;
52+
}
53+
let mut child_nodes_ptr = std::ptr::null_mut();
54+
55+
unsafe {
56+
ffi::SCIPgetChildren(self.scip.raw, &mut child_nodes_ptr, std::ptr::null_mut());
57+
}
58+
let child_nodes_slice = unsafe{std::slice::from_raw_parts(child_nodes_ptr, num_children as usize)};
59+
// put into a Vec and transform to Node
60+
let mut children_vec = Vec::with_capacity(num_children as usize);
61+
for child in child_nodes_slice {
62+
children_vec.push(Node{
63+
raw: *child,
64+
scip: self.scip.clone(),
65+
});
66+
}
67+
Some(children_vec)
68+
}
4569
}
4670

4771
#[cfg(test)]

0 commit comments

Comments
 (0)