ECF 1.5
nqueens.h
1/* nqueens.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/* Memory management */
21struct solution *allocSolution(struct problem *p);
22struct move *allocMove(struct problem *p);
23struct pathState *allocPathState(struct problem *p);
24
25void freeProblem(struct problem *p);
26void freeSolution(struct solution *s);
27void freeMove(struct move *v);
28void freePathState(struct pathState *ps);
29
30/* I/O */
31void printProblem(struct problem *p);
32void printSolution(struct solution *s);
33void printMove(struct move *v);
34void printPathState(struct pathState *ps);
35
36/* Solution generation */
37struct solution *randomSolution(struct solution *s);
38
39/* Solution inspection */
40double getObjectiveValue(struct solution *s);
41
42/* Move generation */
43struct move *randomMove(struct move *v, const struct solution *s);
44
45/* Operations on solutions*/
46struct solution *copySolution(struct solution *dest, const struct solution *src);
47struct solution *applyMove(struct solution *s, const struct move *v);
48
49/* Path generation */
50struct pathState *initPathTo(struct pathState *ps, const struct solution *s1, const struct solution *s2);
51struct pathState *initPathAwayFrom(struct pathState *ps, const struct solution *s);
52struct move *nextRandomMove(struct move *v, struct pathState *ps);
53
54/* Path inspection */
55int getPathLength(const struct pathState *ps);
56
57
58/* This header file contains all problem dependent definitions */
59
60/* Problem-specific instantiation */
61struct problem *newProblem(int n);
62
63struct problem {
64 int n; /* number of queens */
65};
66
67struct solution {
68 struct problem *prob;
69 int *data;
70 int *olddata;
71 int *mod; /* positions modified by moves */
72 int *modi; /* inverse permutation of mod */
73 int nmod; /* no. of positions modified since last evaluation */
74 int n;
75 int objvalue;
76};
77
78struct move {
79 struct problem *prob;
80 int data[2];
81};
82
83struct pathState{
84 struct problem *prob;
85 int *data; /* normalised permutation computed as p2i[p1] */
86 int *datai; /* inverse permutation of data */
87 int *cycle ; /* number ot the cycle each element belons to */
88 int *pos; /* positions in which the solutions differ */
89 int n; /* number of queens / board size */
90 int n_cycles; /* number of cycles in data */
91 int n_diff; /* number of positions in which the solutions differ */
92};
Definition: flowshop.h:78