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-2018 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 email to 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 <assert.h>
24 #include "scip/scip.h"
25 #include "scip/set.h"
26 #include "scip/bandit.h"
27 #include "scip/struct_set.h"
28 #include "scip/struct_scip.h"
29 #include "scip/mem.h"
30 
31 /** includes a bandit algorithm virtual function table */
33  SCIP* scip, /**< SCIP data structure */
34  SCIP_BANDITVTABLE** banditvtable, /**< bandit algorithm virtual function table */
35  const char* name, /**< a name for the algorithm represented by this vtable */
36  SCIP_DECL_BANDITFREE ((*banditfree)), /**< callback to free bandit specific data structures */
37  SCIP_DECL_BANDITSELECT((*banditselect)), /**< selection callback for bandit selector */
38  SCIP_DECL_BANDITUPDATE((*banditupdate)), /**< update callback for bandit algorithms */
39  SCIP_DECL_BANDITRESET ((*banditreset)) /**< update callback for bandit algorithms */
40  )
41 {
42  SCIP_BANDITVTABLE* vtableptr;
43 
44  assert(scip != NULL);
45  assert(banditvtable != NULL);
46 
47  if( SCIPfindBanditvtable(scip, name) != NULL )
48  {
49  SCIPerrorMessage("bandit VTable <%s> already included.\n", name);
50  return SCIP_INVALIDDATA;
51  }
52 
53  SCIP_CALL( SCIPbanditvtableCreate(&vtableptr, name,
54  banditfree, banditselect, banditupdate, banditreset) );
55 
56  SCIP_CALL( SCIPsetIncludeBanditvtable(scip->set, vtableptr) );
57 
58  *banditvtable = vtableptr;
59 
60  return SCIP_OKAY;
61 }
62 
63 /** returns the bandit virtual function table of the given name, or NULL if not existing */
65  SCIP* scip, /**< SCIP data structure */
66  const char* name /**< name of bandit algorithm virtual function table */
67  )
68 {
69  assert(scip != NULL);
70 
71  return SCIPsetFindBanditvtable(scip->set, name);
72 }
73 
74 /** reset the bandit algorithm */
76  SCIP* scip, /**< SCIP data structure */
77  SCIP_BANDIT* bandit, /**< pointer to bandit algorithm data structure */
78  SCIP_Real* priorities, /**< priorities for every action, or NULL if not needed */
79  unsigned int seed /**< initial random seed for bandit selection */
80  )
81 {
82  assert(scip != NULL);
83  assert(bandit != NULL);
84 
85  SCIP_CALL( SCIPbanditReset(SCIPbuffer(scip), bandit, priorities, SCIPinitializeRandomSeed(scip, (int)(seed % INT_MAX))) );
86 
87  return SCIP_OKAY;
88 }
89 
90 /** calls destructor and frees memory of bandit algorithm */
92  SCIP* scip, /**< SCIP data structure */
93  SCIP_BANDIT** bandit /**< pointer to bandit algorithm data structure */
94  )
95 {
96  assert(scip != NULL);
97  assert(bandit != NULL);
98  assert(*bandit != NULL);
99 
100  SCIP_CALL( SCIPbanditFree(SCIPblkmem(scip), bandit) );
101 
102  return SCIP_OKAY;
103 }
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:201
SCIP_RETCODE SCIPsetIncludeBanditvtable(SCIP_SET *set, SCIP_BANDITVTABLE *banditvtable)
Definition: set.c:4150
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
SCIP_BANDITVTABLE * SCIPfindBanditvtable(SCIP *scip, const char *name)
Definition: scip_bandit.c:64
BMS_BUFMEM * SCIPbuffer(SCIP *scip)
Definition: scip.c:46746
#define SCIPerrorMessage
Definition: pub_message.h:45
SCIP_BANDITVTABLE * SCIPsetFindBanditvtable(SCIP_SET *set, const char *name)
Definition: set.c:4172
methods for block memory pools and memory buffers
#define SCIP_DECL_BANDITRESET(x)
Definition: type_bandit.h:73
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip.c:46731
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:350
SCIP main data structure.
unsigned int SCIPinitializeRandomSeed(SCIP *scip, int initialseedvalue)
Definition: scip.c:25905
SCIP_RETCODE SCIPbanditFree(BMS_BLKMEM *blkmem, SCIP_BANDIT **bandit)
Definition: bandit.c:70
SCIP_RETCODE SCIPfreeBandit(SCIP *scip, SCIP_BANDIT **bandit)
Definition: scip_bandit.c:91
SCIP_RETCODE SCIPresetBandit(SCIP *scip, SCIP_BANDIT *bandit, SCIP_Real *priorities, unsigned int seed)
Definition: scip_bandit.c:75
#define SCIP_DECL_BANDITFREE(x)
Definition: type_bandit.h:54
SCIP_SET * set
Definition: struct_scip.h:62
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:32
#define SCIP_Real
Definition: def.h:149
#define SCIP_DECL_BANDITUPDATE(x)
Definition: type_bandit.h:66
#define SCIP_DECL_BANDITSELECT(x)
Definition: type_bandit.h:60
datastructures for global SCIP settings
SCIP callable library.