Scippy

SCIP

Solving Constraint Integer Programs

scip_bandit.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-2024 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 scip_bandit.c
26 * @ingroup OTHER_CFILES
27 * @brief public functions for bandit algorithms
28 * @author Gregor Hendel
29 */
30
31/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
32
33#include "scip/bandit.h"
34#include "scip/pub_message.h"
35#include "scip/scip_bandit.h"
36#include "scip/scip_mem.h"
38#include "scip/set.h"
39#include "scip/struct_scip.h"
40#include "scip/pub_message.h"
41#include "scip/scip_bandit.h"
42#include "scip/scip_mem.h"
44#include "scip/set.h"
45#include "scip/struct_scip.h"
46
47/** includes a bandit algorithm virtual function table */
49 SCIP* scip, /**< SCIP data structure */
50 SCIP_BANDITVTABLE** banditvtable, /**< bandit algorithm virtual function table */
51 const char* name, /**< a name for the algorithm represented by this vtable */
52 SCIP_DECL_BANDITFREE ((*banditfree)), /**< callback to free bandit specific data structures */
53 SCIP_DECL_BANDITSELECT((*banditselect)), /**< selection callback for bandit selector */
54 SCIP_DECL_BANDITUPDATE((*banditupdate)), /**< update callback for bandit algorithms */
55 SCIP_DECL_BANDITRESET ((*banditreset)) /**< update callback for bandit algorithms */
56 )
57{
58 SCIP_BANDITVTABLE* vtableptr;
59
60 assert(scip != NULL);
61 assert(banditvtable != NULL);
62
63 if( SCIPfindBanditvtable(scip, name) != NULL )
64 {
65 SCIPerrorMessage("bandit VTable <%s> already included.\n", name);
66 return SCIP_INVALIDDATA;
67 }
68
69 SCIP_CALL( SCIPbanditvtableCreate(&vtableptr, name,
70 banditfree, banditselect, banditupdate, banditreset) );
71
72 SCIP_CALL( SCIPsetIncludeBanditvtable(scip->set, vtableptr) );
73
74 *banditvtable = vtableptr;
75
76 return SCIP_OKAY;
77}
78
79/** returns the bandit virtual function table of the given name, or NULL if not existing */
81 SCIP* scip, /**< SCIP data structure */
82 const char* name /**< name of bandit algorithm virtual function table */
83 )
84{
85 assert(scip != NULL);
86
87 return SCIPsetFindBanditvtable(scip->set, name);
88}
89
90/** reset the bandit algorithm */
92 SCIP* scip, /**< SCIP data structure */
93 SCIP_BANDIT* bandit, /**< pointer to bandit algorithm data structure */
94 SCIP_Real* priorities, /**< priorities for every action, or NULL if not needed */
95 unsigned int seed /**< initial random seed for bandit selection */
96 )
97{
98 assert(scip != NULL);
99 assert(bandit != NULL);
100
101 SCIP_CALL( SCIPbanditReset(SCIPbuffer(scip), bandit, priorities, SCIPinitializeRandomSeed(scip, seed)) );
102
103 return SCIP_OKAY;
104}
105
106/** calls destructor and frees memory of bandit algorithm */
108 SCIP* scip, /**< SCIP data structure */
109 SCIP_BANDIT** bandit /**< pointer to bandit algorithm data structure */
110 )
111{
112 assert(scip != NULL);
113 assert(bandit != NULL);
114 assert(*bandit != NULL);
115
117
118 return SCIP_OKAY;
119}
SCIP_RETCODE SCIPbanditvtableCreate(SCIP_BANDITVTABLE **banditvtable, const char *name, SCIP_DECL_BANDITFREE((*banditfree)), SCIP_DECL_BANDITSELECT((*banditselect)), SCIP_DECL_BANDITUPDATE((*banditupdate)), SCIP_DECL_BANDITRESET((*banditreset)))
Definition: bandit.c:245
SCIP_RETCODE SCIPbanditFree(BMS_BLKMEM *blkmem, SCIP_BANDIT **bandit)
Definition: bandit.c:80
SCIP_RETCODE SCIPbanditReset(BMS_BUFMEM *bufmem, SCIP_BANDIT *bandit, SCIP_Real *priorities, unsigned int seed)
Definition: bandit.c:109
internal methods for bandit algorithms
#define NULL
Definition: def.h:267
#define SCIP_Real
Definition: def.h:173
#define SCIP_CALL(x)
Definition: def.h:374
SCIP_RETCODE SCIPresetBandit(SCIP *scip, SCIP_BANDIT *bandit, SCIP_Real *priorities, unsigned int seed)
Definition: scip_bandit.c:91
SCIP_BANDITVTABLE * SCIPfindBanditvtable(SCIP *scip, const char *name)
Definition: scip_bandit.c:80
SCIP_RETCODE SCIPincludeBanditvtable(SCIP *scip, SCIP_BANDITVTABLE **banditvtable, const char *name, SCIP_DECL_BANDITFREE((*banditfree)), SCIP_DECL_BANDITSELECT((*banditselect)), SCIP_DECL_BANDITUPDATE((*banditupdate)), SCIP_DECL_BANDITRESET((*banditreset)))
Definition: scip_bandit.c:48
SCIP_RETCODE SCIPfreeBandit(SCIP *scip, SCIP_BANDIT **bandit)
Definition: scip_bandit.c:107
BMS_BUFMEM * SCIPbuffer(SCIP *scip)
Definition: scip_mem.c:72
unsigned int SCIPinitializeRandomSeed(SCIP *scip, unsigned int initialseedvalue)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:57
public methods for message output
#define SCIPerrorMessage
Definition: pub_message.h:64
public methods for bandit algorithms
public methods for memory management
public methods for random numbers
SCIP_RETCODE SCIPsetIncludeBanditvtable(SCIP_SET *set, SCIP_BANDITVTABLE *banditvtable)
Definition: set.c:4450
SCIP_BANDITVTABLE * SCIPsetFindBanditvtable(SCIP_SET *set, const char *name)
Definition: set.c:4472
internal methods for global SCIP settings
SCIP main data structure.
#define SCIP_DECL_BANDITUPDATE(x)
Definition: type_bandit.h:75
#define SCIP_DECL_BANDITFREE(x)
Definition: type_bandit.h:63
#define SCIP_DECL_BANDITSELECT(x)
Definition: type_bandit.h:69
#define SCIP_DECL_BANDITRESET(x)
Definition: type_bandit.h:82
@ SCIP_INVALIDDATA
Definition: type_retcode.h:52
@ SCIP_OKAY
Definition: type_retcode.h:42
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63