ECF 1.5
shd.c
1/* shd.c
2 *
3 * (C) 2018 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#include <stdlib.h>
21#include <gsl/gsl_rng.h>
22#include "shd.h"
23
24extern gsl_rng *rng; /* The single rng instance used by the whole code */
25
26struct solverState {
27 struct problem *p;
28 struct solution *s0, *s1;
29 struct move *v;
30};
31
32struct solverState *newSolver(struct problem *p) {
33 struct solverState *ss;
34 ss = (struct solverState *) malloc(sizeof (struct solverState));
35 ss->p = p;
36 ss->s0 = allocSolution(p);
37 ss->s1 = allocSolution(p);
38 ss->v = allocMove(p);
39 randomSolution(ss->s0);
40 /* Force initialisation of the whole state
41 nextSolverState(ss); */
42 return ss;
43}
44
45void freeSolver(struct solverState *ss) {
46 freeSolution(ss->s0);
47 freeSolution(ss->s1);
48 freeMove(ss->v);
49 free(ss);
50}
51
52struct solverState *nextSolverState(struct solverState *ss) {
53 struct solution *tmp;
54 copySolution(ss->s1, ss->s0);
55 randomMove(ss->v, ss->s1);
56 applyMove(ss->s1, ss->v);
57 if (getObjectiveValue(ss->s1) <= getObjectiveValue(ss->s0)) {
58 tmp = ss->s0;
59 ss->s0 = ss->s1;
60 ss->s1 = tmp;
61 }
62 return ss;
63}
64
65struct solution *getSolverSolution(struct solverState *ss) {
66 return ss->s0;
67}
68
69void printSolverState(struct solverState *ss) {
70 printSolution(ss->s0);
71}
72
Definition: flowshop.h:78