1 #ifndef STRUCTS_H
2 #define STRUCTS_H
3 
4 #ifdef HAVE_PTHREAD
5 #include <pthread.h>
6 #endif
7 
8 #include "librcps.h"
9 #include "slist.h"
10 
11 // XXX perhaps we need an index in most sstructs so that resources[i]->index==i
12 // this would be cool in repair
13 
14 struct rcps_problem {
15 	struct rcps_resource **resources;
16 	int resource_count;
17 	struct rcps_job **jobs;
18 	int job_count;
19 	/* pre-calculated values */
20 	int genome_modes;
21 	int *modes_max;
22 	int genome_alternatives;
23 	int *alternatives_max;
24 	/* fitness calculation mode */
25 	int fitness_mode;
26 	/* weight callback */
27 	int (*weight_callback)(int starttime, int duration, struct rcps_fitness *nominal_weight, void *arg, void *fitness_arg);
28 	/* fitness callback, set up a user defined fitness structure and return a pointer to it */
29 	void *(*fitness_callback_init)(void *fitness_init_arg);
30     /* the argument returned by fitness_callback_init */
31     void *fitness_init_arg;
32     /* fitness callback
33      * fill in the result of the fitness calculation into fitness.
34      * arg is the argument returned by fitness_callback_init  */
35     int (*fitness_callback_result)(struct rcps_fitness *fitness, void *arg);
36 };
37 
38 struct rcps_resource {
39 	char *name;
40 	int type;
41 	int avail;
42 	/* pre-calculated values */
43 	int index;
44 };
45 
46 struct rcps_job {
47 	char *name;
48 	struct rcps_job **successors;
49 	int *successor_types;
50 	int successor_count;
51 	struct rcps_job **predeccessors;
52 	int *predeccessor_types;
53 	int predeccessor_count;
54 	struct rcps_mode **modes;
55 	int mode_count;
56 	/* result */
57 	int res_start;
58 	int res_mode;
59 	/* pre-calculated values */
60 	int genome_position;
61 	int index;
62 	/* fitness calculations */
63 	int weight;
64 	/* time constraints etc. */
65 	int earliest_start;
66 };
67 
68 struct rcps_mode {
69 	int duration;
70     /* duration callback argument */
71 	void *cb_arg;
72 	struct rcps_request **requests;
73 	int request_count;
74     /* weight callback argument */
75     void *weight_cb_arg;
76 
77 };
78 
79 struct rcps_request {
80 	struct rcps_alternative **alternatives;
81 	int alternative_count;
82 	/* result */
83 	int res_alternative;
84 	/* pre-calculated values */
85 	int genome_position;
86 };
87 
88 struct rcps_alternative {
89 	int amount;
90 	struct rcps_resource *resource;
91 };
92 
93 /* please note that the number of modes and alternatives here is not
94  * necessarily the same as in the problem definition, because we do not put
95  * alternatives or modes with only one possibility into the genome */
96 struct rcps_genome {
97 	int *schedule;
98 	int *modes;
99 	int *alternatives;
100 };
101 
102 struct rcps_phenotype {
103 	int overuse_count;
104 	int overuse_amount;
105 	int *job_start;
106     int *job_duration;
107 };
108 
109 struct rcps_individual {
110     struct rcps_fitness fitness;
111 	struct rcps_genome genome;
112 };
113 
114 struct rcps_population {
115 	int size;
116 	struct slist *individuals;
117 };
118 
119 struct rcps_solver {
120 	// this contains a job_count * job_count array
121 	char *predecessor_hash;
122 	// population size and mutation rates
123 	int pop_size;
124 	int mut_sched;
125 	int mut_mode;
126 	int mut_alt;
127 	// the number of parallel jobs
128 	int jobs;
129 	// save the number of reproductions needed by the solver here
130 	int reproductions;
131 	// set to != 0 if the computed schedule is not valid
132 	int warnings;
133 	// the actual population;
134 	struct rcps_population *population;
135 	// progress callback and data
136 	int (*progress_callback)(int generations, struct rcps_fitness fitness, void *arg);
137 	void *cb_arg;
138 	int cb_steps;
139 	// duration callback
140 	int (*duration_callback)(int direction, int starttime,
141 		int nominal_duration, void *arg);
142 	// the lock for multithreading
143 #ifdef HAVE_PTHREAD
144 	pthread_mutex_t lock;
145 #endif
146 };
147 
148 #endif /* STRUCTS_H */
149