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