Blame view

src/utils/flatzinc/actions.h 6.47 KB
94b2b13d   Pedro Roque   PHACT source
1
2
3
4

/*
 * actions.h
 *
4d26a735   Pedro Roque   Increased recogni...
5
 *  Created on: 15/12/2017
94b2b13d   Pedro Roque   PHACT source
6
7
8
9
10
11
12
13
14
 *      Author: pedro
 */

#ifndef SRC_UTILS_FLATZINC_ACTIONS_H
#define SRC_UTILS_FLATZINC_ACTIONS_H

#include "../../config.h"
#include "../../split.h"
#include "../../variables.h"
4d26a735   Pedro Roque   Increased recogni...
15
16

#define FZN_NE2ALL_DIFF 1		// Try to detect MiniZinc ALL DIFFERENT constraints that were changed to FlatZinc NE constraints, and reverse the change
94b2b13d   Pedro Roque   PHACT source
17
#define FZN_REPLACE_BOOL2INT 1	// Set to 1 to ignore bool2int constraints and merge both variables
4d26a735   Pedro Roque   Increased recogni...
18

94b2b13d   Pedro Roque   PHACT source
19
20
21
22
23
24
25
26
#define FZN_VERBOSE 0		// Print some information during the interpretation process
#define FZN_DEBUG 0			// Print some more information from yacc and bison
#define FZN_PRINT_CSP 0		// Print the CSP model loaded from the FZN file
#define FZN_STATS 0			// Print the number of variables, constraints, types of constraints and maximum domain value of the FlatZinc model
#define FZN_MAP_FZN2PHACT 0		// Print PHACT variables and constraints ID followed by the FZN correspondent
#define FZN_LABEL_ALL_VARS 0	// Mark all the CSP variables for labeling
#define FZN_LABEL_DEFINED_VARS 0		// Set for labeling all the variables marked as "is_defined_var"
#define FZN_REMOVE_DUPLICATE_CONSTRS 0	// Remove some duplicated constraints (disabled due to much time increment when dealing with many constraints)
4d26a735   Pedro Roque   Increased recogni...
27
#define FZN_SORT_CONSTR_VARS 0	// For some constraints, sort their constrained variable for FZN file input order
94b2b13d   Pedro Roque   PHACT source
28
#define FZN_REMOVE_ACHIEVED_CONSTRS 0	// Remove some constraints already meet (done by PHACT when initial filtering is enabled)
4d26a735   Pedro Roque   Increased recogni...
29

94b2b13d   Pedro Roque   PHACT source
30
31
#define FZN_MAX_ELEMENTS 300
#define FZN_MAX_ARRAYS 50
4d26a735   Pedro Roque   Increased recogni...
32
33
34
#define FZN_MAX_ANNOTATIONS 50

extern int FZN_OPTIMIZE;	// if the the optimization is for minimize or maximize
94b2b13d   Pedro Roque   PHACT source
35
#define FZN_MINIMIZE 1
4d26a735   Pedro Roque   Increased recogni...
36
37
#define FZN_MAXIMIZE 2

94b2b13d   Pedro Roque   PHACT source
38
39
40
41
typedef struct fzn_object fzn_object;	// FlatZinc object used until identification as an array, constraint or variable
typedef struct fzn_var fzn_var;		// Flatzinc representation of a CSP variable
typedef struct fzn_var fzn_var;		// Flatzinc representation of a CSP variable
typedef struct fzn_array fzn_array;		// Array for storing values that may be the ID of variables or constant values
4d26a735   Pedro Roque   Increased recogni...
42
43
typedef struct fzn_constr fzn_constr;	// Flatzinc representation of a CSP constraint
typedef struct fzn_output_array fzn_output_array;	// output arrays
94b2b13d   Pedro Roque   PHACT source
44
45
typedef struct fzn_search_annotat fzn_search_annotat;	// FZN search annotations

4d26a735   Pedro Roque   Increased recogni...
46
// FlatZinc object used until identification as an array, constraint or variable
94b2b13d   Pedro Roque   PHACT source
47
48
49
50
struct fzn_object {
	char** annots;				// array with all the annotations
	char** annots_aux;			// to extend annotations array
	int next_annot;				// index of the next annotation to add to annotations array
4d26a735   Pedro Roque   Increased recogni...
51
52
	int max_annots;				// maximum current size of the annotations array
	int* elements;				// number of var_idx for arrays and constraints
94b2b13d   Pedro Roque   PHACT source
53
54
	int* elements_aux;			// to extend the elements array
	bool* element_is_var;		// if each element on the elements array is a number or a variable idx
4d26a735   Pedro Roque   Increased recogni...
55
56
57
58
	bool* element_is_var_aux;	// to extend element_is_var array
	int next_element;			// next position to add an element to elements array
	int max_elements;			// current maximum elements in the elements array
	bool is_array;				// true if it is an array
94b2b13d   Pedro Roque   PHACT source
59
60
61
62
63
64
65
66
67
	bool is_constraint;			// true if it is a constraint
	bool is_bool;				// true if it is a boolean
	bool range;					// true if the correspondent variable will have a range domain
	int pos_init_2_array;		// position of elements where second array of elements begins (for bool_clause constraint only)
};


// Flatzinc representation of a CSP variable
struct fzn_var {
94b2b13d   Pedro Roque   PHACT source
68
69
	int* values;
	int* values_aux;
4d26a735   Pedro Roque   Increased recogni...
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
	int max_values;
	int next_position;
	int min;
	int max;
	unsigned int id;
	char* name;
	bool to_label;
	bool var_is_introduced;
	bool is_defined_var;
	int defined_by_constr_idx;
	bool output_var;
	bool ignore;
	int replace_by_v_id;
	bool range;
	bool created;
};

// Flatzinc representation of a CSP constraint
struct fzn_constr {
	char* name;
	unsigned int* vars_id;
	unsigned int* vars_id_aux;
94b2b13d   Pedro Roque   PHACT source
92
93
94
95
	int next_var_to_add;
	int max_vars;
	int* consts;
	int* consts_aux;
4d26a735   Pedro Roque   Increased recogni...
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
	int next_const_to_add;
	int max_consts;
	int defines_var_idx;
	bool ignore;
	bool boundsZ;
	bool boundsR;
	bool boundsD;
	bool domain;
	bool priority;
	bool priority_v_id;
	unsigned int id;
	int pos_init_2_array;		// position of elements where second array of elements begins (for bool_clause constraint only)
};

// Array for storing values that may be the ID of variables or constant values
struct fzn_array {
	int* values;
	int* values_aux;
	int max_values;
94b2b13d   Pedro Roque   PHACT source
115
116
117
118
	int next_position;
	char* name;
	bool output_array;
	bool to_label;
4d26a735   Pedro Roque   Increased recogni...
119
120
121
122
123
124
125
126
127
128
129
	bool var_is_introduced;
	bool is_defined_var;
	bool output_var;
	bool var_array;
};

// Output arrays
struct fzn_output_array {
	unsigned int* vars_id;
	unsigned int* vars_id_aux;
	char *name;
94b2b13d   Pedro Roque   PHACT source
130
131
132
133
	int max_vars;
	int next_position;
};

4d26a735   Pedro Roque   Increased recogni...
134
135
136
137
138
// Search annotations
struct fzn_search_annotat {
	char* search_type;
	char* label_array_name;
	char* label_heur;
94b2b13d   Pedro Roque   PHACT source
139
140
141
142
	char* assign_heur;
	char* search_strategy;
};

4d26a735   Pedro Roque   Increased recogni...
143
144
145
146
147
extern int yylex();
extern int yyparse();
extern FILE* yyin;
void yyerror(const char* s);

94b2b13d   Pedro Roque   PHACT source
148
149
150
151
void parse(char* fzn_file_name);
void fzn_solve();

void fzn_add_val_to_object(int val);
4d26a735   Pedro Roque   Increased recogni...
152
153
void fzn_add_var_or_array_to_object(char* name);
void fzn_set_fzn_obj_range(bool range);
94b2b13d   Pedro Roque   PHACT source
154
void fzn_add_annot_to_object(char* annot);
4d26a735   Pedro Roque   Increased recogni...
155
void fzn_set_2array_init_pos();
94b2b13d   Pedro Roque   PHACT source
156
157
158
void fzn_extend_object_elements();
void fzn_reset_object_elements();

4d26a735   Pedro Roque   Increased recogni...
159
void fzn_new_fzn_obj_array();
94b2b13d   Pedro Roque   PHACT source
160
void fzn_add_var_to_array(char* var_name);
4d26a735   Pedro Roque   Increased recogni...
161
void fzn_add_val_to_array(int value);
94b2b13d   Pedro Roque   PHACT source
162
163
164
165
166
void fzn_array_copy(fzn_array* dest, fzn_array* src, int n_arrays);

int fzn_new_fzn_var_range(int min, int max);
int fzn_new_fzn_obj_var_value(int val);
int fzn_new_fzn_obj_var();
4d26a735   Pedro Roque   Increased recogni...
167
void fzn_vars_copy(fzn_var* dest, fzn_var* src, int n_vs);
94b2b13d   Pedro Roque   PHACT source
168
void fzn_vars_extend();
4d26a735   Pedro Roque   Increased recogni...
169
void fzn_set_var_to_optimize(char* var_name);
94b2b13d   Pedro Roque   PHACT source
170
171
172
173

void fzn_new_output_array();
void fzn_output_array_copy(fzn_output_array* dest, fzn_output_array* src, int n_arrays);
void fzn_add_var_id_to_output_array(unsigned int v_id);
4d26a735   Pedro Roque   Increased recogni...
174

94b2b13d   Pedro Roque   PHACT source
175
void fzn_new_fzn_obj_constr();
4d26a735   Pedro Roque   Increased recogni...
176
void fzn_add_fzn_obj_elem_var_to_constr(int e_idx);
94b2b13d   Pedro Roque   PHACT source
177
178
void fzn_add_fzn_obj_elem_val_to_constr(int e_idx);
void fzn_constrs_copy(fzn_constr* dest, fzn_constr* src, int n_constrs);
4d26a735   Pedro Roque   Increased recogni...
179

94b2b13d   Pedro Roque   PHACT source
180
181
182
183
184
void fzn_add_fzn_obj_search_annot();
void fzn_search_annots_copy(fzn_search_annotat* dest, fzn_search_annotat* src, int n_search_annots);

void fzn_set_var_or_array_to_label(char* name);

4d26a735   Pedro Roque   Increased recogni...
185
void fzn_sort_constr_vars();
94b2b13d   Pedro Roque   PHACT source
186
187

void fzn_new_csp_var(int var_idx);
4d26a735   Pedro Roque   Increased recogni...
188
189
190
191
void fzn_new_csp_constr(int constr_idx);

void fzn_print_csp();
void fzn_map_fzn2phact();
94b2b13d   Pedro Roque   PHACT source
192
void fzn_print_stats();
4d26a735   Pedro Roque   Increased recogni...
193

94b2b13d   Pedro Roque   PHACT source
194
195
196
void fzn_init_search_annots();

#endif /* SRC_UTILS_FLATZINC_ACTIONS_H */
4d26a735   Pedro Roque   Increased recogni...

94b2b13d   Pedro Roque   PHACT source