-
Notifications
You must be signed in to change notification settings - Fork 1
/
item.h
64 lines (46 loc) · 1.05 KB
/
item.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef __ITEM_H__
#define __ITEM_H__
#include "const.h"
#ifdef THREADED
#include <pthread.h>
#endif
struct Item
{
/**
* Each type of restriction, independent of each other
* A Knapsack cannot go over any restriction
*/
Restr *restrictions;
PherDes pdValue;
/**
* How desirable is an item, calculated from value and restrictions
*/
Desirability desirability;
/**
* Declaring the pheromone as _Atomic guarantees no race writes will occur
*/
Pher pheromone;
/**
* The value of the item
*/
Cost value;
#ifdef THREADED
/** the lock of a given item
* for pheromone updating
*/
pthread_mutex_t itemLock;
#endif
};
extern struct Item *universe;
void Item_init(struct Item*);
void Item_updatePdValue(struct Item*);
Desirability get_desirability(Cost, Restr*);
void Item_addPheromone(struct Item*, Pher);
inline void Item_evapPheromone(struct Item *i)
{
i->pheromone *= (1 - PHE_EVAP);
}
void evapPheromones();
void create_universe();
void delete_universe();
#endif