-
Notifications
You must be signed in to change notification settings - Fork 1
/
knapsack.h
62 lines (44 loc) · 1.15 KB
/
knapsack.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
#ifndef __KNAPSACK_H__
#define __KNAPSACK_H__
#include <stdbool.h>
#include "const.h"
struct Knapsack {
/*
* Marks wether or not the sack contains an item
*/
bool *has_item;
/*
* marks the remaining capacity the sack has
*/
Restr *capacity;
/*
* worth of the knapsack, aka. the sum of all items worth
*/
Cost worth;
/*
* number of items in the knapsack
*/
size_t num_items;
};
struct K_item_prob{
ItemId itemid;
//probability to choose this item
Prob prob;
//padding to complete 16 bytes
int32_t __padding;
};
struct Neighbour {
size_t size; //number of items in the neighbourhood
//dynamic structure of all items
//cap is the allocated size, different from the used size above
size_t cap;
struct K_item_prob* items;
};
void Knapsack_init(struct Knapsack*);
void Knapsack_destroy(struct Knapsack*);
bool Knapsack_canAddItem(struct Knapsack*, ItemId);
void Knapsack_addItem(struct Knapsack*, ItemId);
struct Neighbour *createNeighbour(struct Knapsack*);
void deleteNeighbour(struct Neighbour*);
ItemId Neighbour_randSelect(struct Neighbour*);
#endif