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-2020 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file scip_bandit.c
17  * @ingroup OTHER_CFILES
18  * @brief public functions for bandit algorithms
19  * @author Gregor Hendel
20  */
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #include "scip/bandit.h"
25 #include "scip/pub_message.h"
26 #include "scip/scip_bandit.h"
27 #include "scip/scip_mem.h"
28 #include "scip/scip_randnumgen.h"
29 #include "scip/set.h"
30 #include "scip/struct_scip.h"
31 #include "scip/pub_message.h"
32 #include "scip/scip_bandit.h"
33 #include "scip/scip_mem.h"
34 #include "scip/scip_randnumgen.h"
35 #include "scip/set.h"
36 #include "scip/struct_scip.h"
37 
38 /** includes a bandit algorithm virtual function table */
40  SCIP* scip, /**< SCIP data structure */
41  SCIP_BANDITVTABLE** banditvtable, /**< bandit algorithm virtual function table */
42  const char* name, /**< a name for the algorithm represented by this vtable */
43  SCIP_DECL_BANDITFREE ((*banditfree)), /**< callback to free bandit specific data structures */
44  SCIP_DECL_BANDITSELECT((*banditselect)), /**< selection callback for bandit selector */
45  SCIP_DECL_BANDITUPDATE((*banditupdate)), /**< update callback for bandit algorithms */
46  SCIP_DECL_BANDITRESET ((*banditreset)) /**< update callback for bandit algorithms */
47  )
48 {
49  SCIP_BANDITVTABLE* vtableptr;
50 
51  assert(scip != NULL);
52  assert(banditvtable != NULL);
53 
54  if( SCIPfindBanditvtable(scip, name) != NULL )
55  {
56  SCIPerrorMessage("bandit VTable <%s> already included.\n", name);
57  return SCIP_INVALIDDATA;
58  }
59 
60  SCIP_CALL( SCIPbanditvtableCreate(&vtableptr, name,
61  banditfree, banditselect, banditupdate, banditreset) );
62 
63  SCIP_CALL( SCIPsetIncludeBanditvtable(scip->set, vtableptr) );
64 
65  *banditvtable = vtableptr;
66 
67  return SCIP_OKAY;
68 }
69 
70 /** returns the bandit virtual function table of the given name, or NULL if not existing */
72  SCIP* scip, /**< SCIP data structure */
73  const char* name /**< name of bandit algorithm virtual function table */
74  )
75 {
76  assert(scip != NULL);
77 
78  return SCIPsetFindBanditvtable(scip->set, name);
79 }
80 
81 /** reset the bandit algorithm */
83  SCIP* scip, /**< SCIP data structure */
84  SCIP_BANDIT* bandit, /**< pointer to bandit algorithm data structure */
85  SCIP_Real* priorities, /**< priorities for every action, or NULL if not needed */
86  unsigned int seed /**< initial random seed for bandit selection */
87  )
88 {
89  assert(scip != NULL);
90  assert(bandit != NULL);
91 
92  SCIP_CALL( SCIPbanditReset(SCIPbuffer(scip), bandit, priorities, SCIPinitializeRandomSeed(scip, seed)) );
93 
94  return SCIP_OKAY;
95 }
96 
97 /** calls destructor and frees memory of bandit algorithm */
99  SCIP* scip, /**< SCIP data structure */
100  SCIP_BANDIT** bandit /**< pointer to bandit algorithm data structure */
101  )
102 {
103  assert(scip != NULL);
104  assert(bandit != NULL);
105  assert(*bandit != NULL);
106 
107  SCIP_CALL( SCIPbanditFree(SCIPblkmem(scip), bandit) );
108 
109  return SCIP_OKAY;
110 }
SCIP_RETCODE SCIPfreeBandit(SCIP *scip, SCIP_BANDIT **bandit)
Definition: scip_bandit.c:98
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:236
public methods for memory management
SCIP_RETCODE SCIPsetIncludeBanditvtable(SCIP_SET *set, SCIP_BANDITVTABLE *banditvtable)
Definition: set.c:4364
internal methods for bandit algorithms
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
SCIP_RETCODE SCIPbanditReset(BMS_BUFMEM *bufmem, SCIP_BANDIT *bandit, SCIP_Real *priorities, unsigned int seed)
Definition: bandit.c:100
unsigned int SCIPinitializeRandomSeed(SCIP *scip, unsigned int initialseedvalue)
#define SCIPerrorMessage
Definition: pub_message.h:55
SCIP_BANDITVTABLE * SCIPsetFindBanditvtable(SCIP_SET *set, const char *name)
Definition: set.c:4386
#define SCIP_DECL_BANDITRESET(x)
Definition: type_bandit.h:73
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:48
SCIP_BANDITVTABLE * SCIPfindBanditvtable(SCIP *scip, const char *name)
Definition: scip_bandit.c:71
#define NULL
Definition: lpi_spx1.cpp:155
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:364
SCIP main data structure.
SCIP_RETCODE SCIPresetBandit(SCIP *scip, SCIP_BANDIT *bandit, SCIP_Real *priorities, unsigned int seed)
Definition: scip_bandit.c:82
BMS_BUFMEM * SCIPbuffer(SCIP *scip)
Definition: scip_mem.c:63
SCIP_RETCODE SCIPbanditFree(BMS_BLKMEM *blkmem, SCIP_BANDIT **bandit)
Definition: bandit.c:71
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:39
public methods for bandit algorithms
public methods for random numbers
#define SCIP_DECL_BANDITFREE(x)
Definition: type_bandit.h:54
SCIP_SET * set
Definition: struct_scip.h:63
public methods for message output
#define SCIP_Real
Definition: def.h:163
#define SCIP_DECL_BANDITUPDATE(x)
Definition: type_bandit.h:66
#define SCIP_DECL_BANDITSELECT(x)
Definition: type_bandit.h:60