File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 11use crate :: ffi;
22use crate :: scip:: ScipPtr ;
3+ use std:: num;
34use 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) ]
You can’t perform that action at this time.
0 commit comments