ECF 1.5
knapsack.h
1/* knapsack.h
2 *
3 * (C) 2018 Eva Tuba <etuba@ieee.org> and Carlos M. Fonseca <cmfonsec@dei.uc.pt>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20
21/* Problem instantiation - function arguments are purposely left unspecified */
22struct problem *newProblem();
23
24/* Memory management */
25struct solution *allocSolution(struct problem *p);
26struct move *allocMove(struct problem *p);
27struct pathState *allocPathState(struct problem *p);
28
29void freeProblem(struct problem *p);
30void freeSolution(struct solution *s);
31void freeMove(struct move *v);
32void freePathState(struct pathState *ps);
33
34/* I/O */
35void printProblem(struct problem *p);
36void printSolution(struct solution *s);
37void printMove(struct move *v);
38void printPathState(struct pathState *ps);
39
40/* Solution generation */
41struct solution *randomSolution(struct solution *s);
42
43/* Solution inspection */
44double getObjectiveValue(struct solution *s);
45
46/* Move generation */
47struct move *randomMove(struct move *v, const struct solution *s);
48
49/* Operations on solutions*/
50struct solution *copySolution(struct solution *dest, const struct solution *src);
51struct solution *applyMove(struct solution *s, const struct move *v);
52
53/* Path generation */
54struct pathState *initPathTo(struct pathState *ps, const struct solution *s1, const struct solution *s2);
55struct pathState *initPathAwayFrom(struct pathState *ps, const struct solution *s);
56struct move *nextRandomMove(struct move *v, struct pathState *ps);
57
58/* Path inspection */
59int getPathLength(const struct pathState *ps);
60
61
62/* This header file contains all problem dependent definitions */
63
64/* Problem-specific instantiation
65 *
66 * Input file format as described in http://artemisa.unicauca.edu.co/~johnyortega/instances_01_KP/
67 */
68struct problem *newProblem(const char *filename);
69
70
71struct problem {
72 int *weight; /* array of size n, weights of items */
73 int *profit; /* array of size n, profits of items */
74 int n; /* number of items */
75 int capacity; /* maximal weight of a sack */
76};
77
78struct solution {
79 struct problem *prob;
80 char *data;
81 int n;
82 int objvalue;
83 int weight;
84 int profit;
85};
86
87struct move {
88 struct problem *prob;
89 int data;
90};
91
92struct pathState {
93 struct problem *prob;
94 int *pos; /* indices of the bits in which the solutions differ */
95 int n;
96 int distance;
97};
Definition: flowshop.h:78