SCIP

    Solving Constraint Integer Programs

    nodesel_breadthfirst.c
    Go to the documentation of this file.
    1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    2/* */
    3/* This file is part of the program and library */
    4/* SCIP --- Solving Constraint Integer Programs */
    5/* */
    6/* Copyright (c) 2002-2026 Zuse Institute Berlin (ZIB) */
    7/* */
    8/* Licensed under the Apache License, Version 2.0 (the "License"); */
    9/* you may not use this file except in compliance with the License. */
    10/* You may obtain a copy of the License at */
    11/* */
    12/* http://www.apache.org/licenses/LICENSE-2.0 */
    13/* */
    14/* Unless required by applicable law or agreed to in writing, software */
    15/* distributed under the License is distributed on an "AS IS" BASIS, */
    16/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
    17/* See the License for the specific language governing permissions and */
    18/* limitations under the License. */
    19/* */
    20/* You should have received a copy of the Apache-2.0 license */
    21/* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
    22/* */
    23/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    24
    25/**@file nodesel_breadthfirst.h
    26 * @ingroup DEFPLUGINS_NODESEL
    27 * @ingroup NODESELECTORS
    28 * @brief node selector for breadth-first search
    29 * @author Stefan Heinz
    30 * @author Gregor Hendel
    31 *
    32 * This node selector performs breadth-first search, i.e., it completely evaluates an entire level of the search tree before
    33 * proceeding to the next level. At one level, nodes are processed in the order they were created by the branching rule.
    34 */
    35
    36/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
    37
    39#include "scip/pub_message.h"
    40#include "scip/pub_nodesel.h"
    41#include "scip/pub_tree.h"
    42#include "scip/scip_message.h"
    43#include "scip/scip_nodesel.h"
    44#include "scip/scip_tree.h"
    45
    46
    47#define NODESEL_NAME "breadthfirst"
    48#define NODESEL_DESC "breadth first search"
    49#define NODESEL_STDPRIORITY -10000
    50#define NODESEL_MEMSAVEPRIORITY -1000000
    51
    52/*
    53 * Callback methods
    54 */
    55
    56/** copy method for node selector plugins (called when SCIP copies plugins) */
    57static
    58SCIP_DECL_NODESELCOPY(nodeselCopyBreadthfirst)
    59{ /*lint --e{715}*/
    60 assert(scip != NULL);
    61 assert(nodesel != NULL);
    62
    64
    65 /* call inclusion method of node selector */
    67
    68 return SCIP_OKAY;
    69}
    70
    71/** node selection method of node selector */
    72static
    73SCIP_DECL_NODESELSELECT(nodeselSelectBreadthfirst)
    74{ /*lint --e{715}*/
    75 assert(nodesel != NULL);
    76 assert(scip != NULL);
    77 assert(selnode != NULL);
    78
    80
    81 /* siblings come before leaves at the same level. Sometimes it can occur that no leaves are left except for children */
    82 *selnode = SCIPgetBestSibling(scip);
    83 if( *selnode == NULL )
    84 {
    85 *selnode = SCIPgetBestLeaf(scip);
    86 if( *selnode == NULL )
    87 *selnode=SCIPgetBestChild(scip);
    88 }
    89 if( *selnode != NULL )
    90 {
    91 SCIPdebugMsg(scip, "Selecting next node number %" SCIP_LONGINT_FORMAT " at depth %d\n", SCIPnodeGetNumber(*selnode), SCIPnodeGetDepth(*selnode));
    92 }
    93
    94 return SCIP_OKAY;
    95}
    96
    97
    98/** node comparison method of breadth first search: nodes with lower depth are preferred; in case of a tie, the node
    99 * which was created earlier (and therefore has a smaller node number) is preferred */
    100static
    101SCIP_DECL_NODESELCOMP(nodeselCompBreadthfirst)
    102{ /*lint --e{715}*/
    103 int depth1;
    104 int depth2;
    105
    106 assert(nodesel != NULL);
    107 assert(scip != NULL);
    108
    109 depth1 = SCIPnodeGetDepth(node1);
    110 depth2 = SCIPnodeGetDepth(node2);
    111
    112 /* if depths differ, prefer node with smaller depth */
    113 if( depth1 < depth2 )
    114 return -1;
    115 else if( depth1 > depth2 )
    116 return +1;
    117 else
    118 {
    119 /* depths are equal; prefer node with smaller number */
    120 SCIP_Longint number1;
    121 SCIP_Longint number2;
    122
    123 number1 = SCIPnodeGetNumber(node1);
    124 number2 = SCIPnodeGetNumber(node2);
    125 assert(number1 != number2);
    126
    127 if( number1 < number2 )
    128 return -1;
    129 else
    130 return +1;
    131 }
    132}
    133
    134/*
    135 * breadth first specific interface methods
    136 */
    137
    138/** creates the node selector for breadth first search and includes it in SCIP */
    140 SCIP* scip /**< SCIP data structure */
    141 )
    142{
    143 SCIP_NODESEL* nodesel;
    144
    145 /* include node selector */
    147 nodeselSelectBreadthfirst, nodeselCompBreadthfirst, NULL) );
    148
    149 assert(nodesel != NULL);
    150
    151 /* set non-fundamental callback functions via setter functions */
    152 SCIP_CALL ( SCIPsetNodeselCopy(scip, nodesel, nodeselCopyBreadthfirst) );
    153
    154 return SCIP_OKAY;
    155}
    #define NULL
    Definition: def.h:257
    #define SCIP_Longint
    Definition: def.h:150
    #define SCIP_STRINGEQ(name, reference, retcode)
    Definition: def.h:454
    #define SCIP_LONGINT_FORMAT
    Definition: def.h:157
    #define SCIP_CALL(x)
    Definition: def.h:364
    #define SCIPdebugMsg
    Definition: scip_message.h:78
    SCIP_RETCODE SCIPincludeNodeselBreadthfirst(SCIP *scip)
    SCIP_Longint SCIPnodeGetNumber(SCIP_NODE *node)
    Definition: tree.c:8513
    int SCIPnodeGetDepth(SCIP_NODE *node)
    Definition: tree.c:8523
    SCIP_RETCODE SCIPincludeNodeselBasic(SCIP *scip, SCIP_NODESEL **nodesel, const char *name, const char *desc, int stdpriority, int memsavepriority, SCIP_DECL_NODESELSELECT((*nodeselselect)), SCIP_DECL_NODESELCOMP((*nodeselcomp)), SCIP_NODESELDATA *nodeseldata)
    Definition: scip_nodesel.c:111
    SCIP_RETCODE SCIPsetNodeselCopy(SCIP *scip, SCIP_NODESEL *nodesel, SCIP_DECL_NODESELCOPY((*nodeselcopy)))
    Definition: scip_nodesel.c:146
    const char * SCIPnodeselGetName(SCIP_NODESEL *nodesel)
    Definition: nodesel.c:1195
    SCIP_NODE * SCIPgetBestSibling(SCIP *scip)
    Definition: scip_tree.c:336
    SCIP_NODE * SCIPgetBestChild(SCIP *scip)
    Definition: scip_tree.c:320
    SCIP_NODE * SCIPgetBestLeaf(SCIP *scip)
    Definition: scip_tree.c:352
    #define NODESEL_NAME
    static SCIP_DECL_NODESELCOMP(nodeselCompBreadthfirst)
    #define NODESEL_MEMSAVEPRIORITY
    static SCIP_DECL_NODESELSELECT(nodeselSelectBreadthfirst)
    #define NODESEL_STDPRIORITY
    #define NODESEL_DESC
    static SCIP_DECL_NODESELCOPY(nodeselCopyBreadthfirst)
    node selector for breadth-first search
    public methods for message output
    public methods for node selectors
    public methods for branch and bound tree
    public methods for message handling
    public methods for node selector plugins
    public methods for the branch-and-bound tree
    @ SCIP_OKAY
    Definition: type_retcode.h:42
    @ SCIP_INVALIDCALL
    Definition: type_retcode.h:51
    enum SCIP_Retcode SCIP_RETCODE
    Definition: type_retcode.h:63