SCIP

    Solving Constraint Integer Programs

    nodesel_dfs.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_dfs.c
    26 * @ingroup DEFPLUGINS_NODESEL
    27 * @brief node selector for depth first search
    28 * @author Tobias Achterberg
    29 */
    30
    31/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
    32
    33#include "scip/nodesel_dfs.h"
    34#include "scip/pub_message.h"
    35#include "scip/pub_nodesel.h"
    36#include "scip/pub_tree.h"
    37#include "scip/scip_message.h"
    38#include "scip/scip_nodesel.h"
    39#include "scip/scip_tree.h"
    40
    41
    42#define NODESEL_NAME "dfs"
    43#define NODESEL_DESC "depth first search"
    44#define NODESEL_STDPRIORITY 0
    45#define NODESEL_MEMSAVEPRIORITY 100000
    46
    47
    48/*
    49 * Callback methods
    50 */
    51
    52/** copy method for node selector plugins (called when SCIP copies plugins) */
    53static
    54SCIP_DECL_NODESELCOPY(nodeselCopyDfs)
    55{ /*lint --e{715}*/
    56 assert(scip != NULL);
    57 assert(nodesel != NULL);
    58
    60
    61 /* call inclusion method of node selector */
    63
    64 return SCIP_OKAY;
    65}
    66
    67
    68/** node selection method of node selector */
    69static
    70SCIP_DECL_NODESELSELECT(nodeselSelectDfs)
    71{ /*lint --e{715}*/
    72 assert(nodesel != NULL);
    73 assert(scip != NULL);
    74 assert(selnode != NULL);
    75
    77
    78 *selnode = SCIPgetPrioChild(scip);
    79 if( *selnode == NULL )
    80 {
    81 *selnode = SCIPgetPrioSibling(scip);
    82 if( *selnode == NULL )
    83 {
    84 SCIPdebugMsg(scip, "select best leaf\n");
    85 *selnode = SCIPgetBestLeaf(scip);
    86 }
    87
    88 SCIPdebugMsg(scip, "select best sibling leaf\n");
    89 }
    90
    91 return SCIP_OKAY;
    92}
    93
    94
    95/** node comparison method of node selector */
    96static
    97SCIP_DECL_NODESELCOMP(nodeselCompDfs)
    98{ /*lint --e{715}*/
    99 int depth1;
    100 int depth2;
    101
    102 assert(nodesel != NULL);
    103 assert(scip != NULL);
    104
    105 depth1 = SCIPnodeGetDepth(node1);
    106 depth2 = SCIPnodeGetDepth(node2);
    107 if( depth1 > depth2 )
    108 return -1;
    109 else if( depth1 < depth2 )
    110 return +1;
    111 else
    112 {
    113 SCIP_Real lowerbound1;
    114 SCIP_Real lowerbound2;
    115
    116 lowerbound1 = SCIPnodeGetLowerbound(node1);
    117 lowerbound2 = SCIPnodeGetLowerbound(node2);
    118 if( lowerbound1 < lowerbound2 )
    119 return -1;
    120 else if( lowerbound1 > lowerbound2 )
    121 return +1;
    122 else
    123 return 0;
    124 }
    125}
    126
    127
    128/*
    129 * dfs specific interface methods
    130 */
    131
    132/** creates the node selector for depth first search and includes it in SCIP */
    134 SCIP* scip /**< SCIP data structure */
    135 )
    136{
    137 SCIP_NODESEL* nodesel;
    138
    139 /* include node selector */
    141 nodeselSelectDfs, nodeselCompDfs, NULL) );
    142
    143 assert(nodesel != NULL);
    144
    145 SCIP_CALL( SCIPsetNodeselCopy(scip, nodesel, nodeselCopyDfs) );
    146
    147 return SCIP_OKAY;
    148}
    #define NULL
    Definition: def.h:257
    #define SCIP_STRINGEQ(name, reference, retcode)
    Definition: def.h:454
    #define SCIP_Real
    Definition: def.h:165
    #define SCIP_CALL(x)
    Definition: def.h:364
    #define SCIPdebugMsg
    Definition: scip_message.h:78
    SCIP_RETCODE SCIPincludeNodeselDfs(SCIP *scip)
    Definition: nodesel_dfs.c:133
    SCIP_Real SCIPnodeGetLowerbound(SCIP_NODE *node)
    Definition: tree.c:8533
    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 * SCIPgetPrioSibling(SCIP *scip)
    Definition: scip_tree.c:304
    SCIP_NODE * SCIPgetPrioChild(SCIP *scip)
    Definition: scip_tree.c:288
    SCIP_NODE * SCIPgetBestLeaf(SCIP *scip)
    Definition: scip_tree.c:352
    static SCIP_DECL_NODESELCOMP(nodeselCompDfs)
    Definition: nodesel_dfs.c:97
    #define NODESEL_NAME
    Definition: nodesel_dfs.c:42
    static SCIP_DECL_NODESELCOPY(nodeselCopyDfs)
    Definition: nodesel_dfs.c:54
    #define NODESEL_MEMSAVEPRIORITY
    Definition: nodesel_dfs.c:45
    #define NODESEL_STDPRIORITY
    Definition: nodesel_dfs.c:44
    #define NODESEL_DESC
    Definition: nodesel_dfs.c:43
    static SCIP_DECL_NODESELSELECT(nodeselSelectDfs)
    Definition: nodesel_dfs.c:70
    node selector for depth 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