@@ -28,6 +28,7 @@ ColoringSmt<ValueType>::ColoringSmt(
28
28
solver(ctx), harmonizing_variable(ctx), enable_harmonization(enable_harmonization) {
29
29
30
30
timers[__FUNCTION__].start ();
31
+ timers[" ColoringSmt::0" ].start ();
31
32
32
33
for (uint64_t state = 0 ; state < numStates (); ++state) {
33
34
for (uint64_t choice = row_groups[state]; choice < row_groups[state+1 ]; ++choice) {
@@ -60,17 +61,6 @@ ColoringSmt<ValueType>::ColoringSmt(
60
61
STORM_LOG_THROW (variable_found, storm::exceptions::UnexpectedException, " Unexpected variable name." );
61
62
}
62
63
63
- // create substitution variables
64
- z3::expr_vector state_substitution_variables (ctx);
65
- z3::expr_vector choice_substitution_variables (ctx);
66
- for (auto const & name: variable_name) {
67
- z3::expr variable = ctx.int_const (name.c_str ());
68
- state_substitution_variables.push_back (variable);
69
- choice_substitution_variables.push_back (variable);
70
- }
71
- z3::expr action_substitution_variable = ctx.int_const (" act" );
72
- choice_substitution_variables.push_back (action_substitution_variable);
73
-
74
64
// create the tree
75
65
uint64_t num_nodes = tree_list.size ();
76
66
this ->num_actions = *std::max_element (choice_to_action.begin (),choice_to_action.end ())+1 ;
@@ -81,13 +71,12 @@ ColoringSmt<ValueType>::ColoringSmt(
81
71
" Inner node has only one child."
82
72
);
83
73
if (child_true != num_nodes) {
84
- tree.push_back (std::make_shared<InnerNode>(node,ctx,this ->variable_name ,this ->variable_domain ,state_substitution_variables ));
74
+ tree.push_back (std::make_shared<InnerNode>(node,ctx,this ->variable_name ,this ->variable_domain ));
85
75
} else {
86
- tree.push_back (std::make_shared<TerminalNode>(node,ctx,this ->variable_name ,this ->variable_domain ,this ->num_actions ,action_substitution_variable ));
76
+ tree.push_back (std::make_shared<TerminalNode>(node,ctx,this ->variable_name ,this ->variable_domain ,this ->num_actions ));
87
77
}
88
78
}
89
79
getRoot ()->createTree (tree_list,tree);
90
-
91
80
getRoot ()->createHoles (family);
92
81
harmonizing_variable = ctx.int_const (" __harm__" );
93
82
getRoot ()->createPaths (harmonizing_variable);
@@ -118,14 +107,15 @@ ColoringSmt<ValueType>::ColoringSmt(
118
107
STORM_LOG_THROW (domain_option_found, storm::exceptions::UnexpectedException, " Hole option not found." );
119
108
}
120
109
}
110
+ timers[" ColoringSmt::0" ].stop ();
121
111
122
112
// create choice colors
123
- timers[" ColoringSmt:: create choice colors" ].start ();
113
+ timers[" ColoringSmt::1 create choice colors" ].start ();
114
+ // std::cout << "ColoringSmt::1 create choice colors" << std::endl << std::flush;
124
115
125
116
for (std::vector<bool > const & path: getRoot ()->paths ) {
126
117
path_action_hole.push_back (getRoot ()->getPathActionHole (path));
127
118
}
128
-
129
119
choice_path_label.resize (numChoices ());
130
120
for (uint64_t state: state_is_relevant) {
131
121
for (uint64_t choice = row_groups[state]; choice < row_groups[state+1 ]; ++choice) {
@@ -136,111 +126,121 @@ ColoringSmt<ValueType>::ColoringSmt(
136
126
}
137
127
}
138
128
139
- std::vector<z3::expr_vector> state_path_expression;
129
+ std::vector<const TerminalNode*> terminals;
130
+ for (uint64_t path = 0 ; path < numPaths (); ++path) {
131
+ terminals.push_back (getRoot ()->getTerminal (getRoot ()->paths [path]));
132
+ }
133
+
134
+ // allocate array for path expressions
135
+ uint64_t longest_path = 0 ;
136
+ for (uint64_t path = 0 ; path < numPaths (); ++path) {
137
+ longest_path = std::max (longest_path,getRoot ()->paths [path].size ());
138
+ }
139
+ z3::expr_vector state_valuation_int (ctx);
140
+ z3::array<Z3_ast> clause_array (longest_path-1 +num_actions);
141
+
142
+ getRoot ()->substituteActionExpressions ();
143
+ choice_path_expresssion.resize (numChoices ());
140
144
for (uint64_t state = 0 ; state < numStates (); ++state) {
141
- state_path_expression.push_back (z3::expr_vector (ctx));
142
145
if (not state_is_relevant[state]) {
143
146
continue ;
144
147
}
145
- getRoot ()->createPrefixSubstitutions (state_valuation[state]);
146
- for (uint64_t path = 0 ; path < numPaths (); ++path) {
147
- z3::expr_vector evaluated (ctx);
148
- getRoot ()->substitutePrefixExpression (getRoot ()->paths [path], evaluated);
149
- state_path_expression[state].push_back (z3::mk_or (evaluated));
150
- }
151
- }
152
- std::vector<z3::expr_vector> action_path_expression;
153
- for (uint64_t action = 0 ; action < this ->num_actions ; ++action) {
154
- action_path_expression.push_back (z3::expr_vector (ctx));
155
- for (uint64_t path = 0 ; path < numPaths (); ++path) {
156
- z3::expr evaluated = getRoot ()->substituteActionExpression (getRoot ()->paths [path], action);
157
- action_path_expression[action].push_back (evaluated);
158
- }
159
- }
160
148
161
- std::vector<std::vector<uint64_t >> state_dont_care_actions (numStates ());
162
- for (uint64_t state: state_is_relevant) {
163
- state_dont_care_actions[state].push_back (dont_care_action);
164
- for (uint64_t action: ~state_available_actions[state]) {
165
- state_dont_care_actions[state].push_back (action);
149
+ for (uint64_t value: state_valuation[state]) {
150
+ state_valuation_int.push_back (ctx.int_val (value));
166
151
}
167
- }
168
-
152
+ timers[" ColoringSmt::1-2 createPrefixSubstitutions" ].start ();
153
+ getRoot ()->createPrefixSubstitutions (state_valuation[state], state_valuation_int);
154
+ timers[" ColoringSmt::1-2 createPrefixSubstitutions" ].stop ();
155
+ state_valuation_int.resize (0 );
169
156
170
- for (uint64_t state = 0 ; state < numStates (); ++state) {
171
- for (uint64_t choice = row_groups[state]; choice < row_groups[state+1 ]; ++choice) {
172
- choice_path_expresssion.push_back (z3::expr_vector (ctx));
173
- if (not state_is_relevant[state]) {
174
- continue ;
175
- }
176
- uint64_t action = choice_to_action[choice];
177
- for (uint64_t path = 0 ; path < numPaths (); ++path) {
178
- z3::expr action_selection = action_path_expression[action][path];
157
+ timers[" ColoringSmt::1-3" ].start ();
158
+ for (uint64_t path = 0 ; path < numPaths (); ++path) {
159
+ timers[" ColoringSmt::1-3-1" ].start ();
160
+ getRoot ()->substitutePrefixExpression (getRoot ()->paths [path], clause_array);
161
+ timers[" ColoringSmt::1-3-1" ].stop ();
162
+
163
+ timers[" ColoringSmt::1-3-2" ].start ();
164
+ for (uint64_t choice = row_groups[state]; choice < row_groups[state+1 ]; ++choice) {
165
+ timers[" ColoringSmt::1-3-2-1" ].start ();
166
+ uint64_t num_clauses = getRoot ()->paths [path].size ()-1 ;
167
+ uint64_t action = choice_to_action[choice];
168
+ clause_array[num_clauses++] = terminals[path]->action_expression [action];
169
+ timers[" ColoringSmt::1-3-2-1" ].stop ();
170
+ timers[" ColoringSmt::1-3-2-2" ].start ();
179
171
if (action == dont_care_action) {
180
- action_selection = getRoot ()->substituteActionExpression (getRoot ()->paths [path], state_dont_care_actions[state]);
172
+ for (uint64_t unavailable_action: ~state_available_actions[state]) {
173
+ clause_array[num_clauses++] = terminals[path]->action_expression [unavailable_action];
174
+ }
181
175
}
182
- choice_path_expresssion[choice].push_back (state_path_expression[state][path] or action_selection);
176
+ timers[" ColoringSmt::1-3-2-2" ].stop ();
177
+ choice_path_expresssion[choice].push_back (z3::expr (ctx, Z3_mk_or (ctx, num_clauses, clause_array.ptr ())));
178
+ // choice_path_expresssion[choice].push_back(Z3_mk_or(ctx, num_clauses, clause_array.ptr()));
183
179
}
180
+ timers[" ColoringSmt::1-3-2" ].stop ();
184
181
}
182
+ timers[" ColoringSmt::1-3" ].stop ();
185
183
}
186
- timers[" ColoringSmt:: create choice colors" ].stop ();
184
+ timers[" ColoringSmt::1 create choice colors" ].stop ();
187
185
188
186
if (not this ->enable_harmonization ) {
189
187
timers[__FUNCTION__].stop ();
190
188
return ;
191
189
}
192
190
193
- timers[" ColoringSmt:: create harmonizing variants" ].start ();
194
-
191
+ timers[" ColoringSmt::2 create harmonizing variants" ].start ();
192
+ // std::cout << "ColoringSmt::2 create harmonizing variants" << std::endl << std::flush;
195
193
196
- // create harmonizing expressions
197
- std::vector<z3::expr_vector> state_path_expression_harmonizing ;
194
+ getRoot ()-> substituteActionExpressionsHarmonizing (harmonizing_variable);
195
+ choice_path_expresssion_harm. resize ( numChoices ()) ;
198
196
for (uint64_t state = 0 ; state < numStates (); ++state) {
199
- state_path_expression_harmonizing.push_back (z3::expr_vector (ctx));
200
197
if (not state_is_relevant[state]) {
201
198
continue ;
202
199
}
203
- // create state substitution
204
- z3::expr_vector substitution_expr (ctx);
200
+
205
201
for (uint64_t value: state_valuation[state]) {
206
- substitution_expr.push_back (ctx.int_val (value));
207
- }
208
- getRoot ()->createPrefixSubstitutionsHarmonizing (substitution_expr);
209
- for (uint64_t path = 0 ; path < numPaths (); ++path) {
210
- z3::expr_vector evaluated (ctx);
211
- getRoot ()->substitutePrefixExpressionHarmonizing (getRoot ()->paths [path], evaluated);
212
- state_path_expression_harmonizing[state].push_back (z3::mk_or (evaluated));
202
+ state_valuation_int.push_back (ctx.int_val (value));
213
203
}
214
- }
215
- std::vector<z3::expr_vector> action_path_expression_harmonizing;
216
- for (uint64_t action = 0 ; action < num_actions; ++action) {
217
- action_path_expression_harmonizing.push_back (z3::expr_vector (ctx));
204
+ timers[" ColoringSmt::2-2 createPrefixSubstitutionsHarmonizing" ].start ();
205
+ getRoot ()->createPrefixSubstitutionsHarmonizing (state_valuation[state], state_valuation_int, harmonizing_variable);
206
+ timers[" ColoringSmt::2-2 createPrefixSubstitutionsHarmonizing" ].stop ();
207
+ state_valuation_int.resize (0 );
208
+
209
+ timers[" ColoringSmt::2-3" ].start ();
218
210
for (uint64_t path = 0 ; path < numPaths (); ++path) {
219
- z3::expr evaluated = getRoot ()->substituteActionExpressionHarmonizing (getRoot ()->paths [path], action, harmonizing_variable);
220
- action_path_expression_harmonizing[action].push_back (evaluated);
221
- }
222
- }
223
- for (uint64_t state = 0 ; state < numStates (); ++state) {
224
- for (uint64_t choice = row_groups[state]; choice < row_groups[state+1 ]; ++choice) {
225
- choice_path_expresssion_harm.push_back (z3::expr_vector (ctx));
226
- if (not state_is_relevant[state]) {
227
- continue ;
228
- }
229
- uint64_t action = choice_to_action[choice];
230
- for (uint64_t path = 0 ; path < numPaths (); ++path) {
231
- z3::expr action_selection = action_path_expression_harmonizing[action][path];
211
+ timers[" ColoringSmt::2-3-1" ].start ();
212
+ getRoot ()->substitutePrefixExpressionHarmonizing (getRoot ()->paths [path], clause_array);
213
+ timers[" ColoringSmt::2-3-1" ].stop ();
214
+
215
+ timers[" ColoringSmt::2-3-2" ].start ();
216
+ for (uint64_t choice = row_groups[state]; choice < row_groups[state+1 ]; ++choice) {
217
+ uint64_t action = choice_to_action[choice];
218
+ uint64_t num_clauses = getRoot ()->paths [path].size ()-1 ;
219
+ clause_array[num_clauses++] = terminals[path]->action_expression_harmonizing [action];
232
220
if (action == dont_care_action) {
233
- action_selection = getRoot ()->substituteActionExpressionHarmonizing (getRoot ()->paths [path], state_dont_care_actions[state], harmonizing_variable);
221
+ for (uint64_t unavailable_action: ~state_available_actions[state]) {
222
+ clause_array[num_clauses++] = terminals[path]->action_expression_harmonizing [unavailable_action];
223
+ }
234
224
}
235
- choice_path_expresssion_harm[choice].push_back (state_path_expression_harmonizing[state][path] or action_selection);
225
+ choice_path_expresssion_harm[choice].push_back (z3::expr (ctx, Z3_mk_or (ctx, num_clauses, clause_array.ptr ())));
226
+ // choice_path_expresssion_harm[choice].push_back(Z3_mk_or(ctx, num_clauses, clause_array.ptr()));
236
227
}
228
+ timers[" ColoringSmt::2-3-2" ].stop ();
237
229
}
230
+ timers[" ColoringSmt::2-3" ].stop ();
238
231
}
239
- timers[" ColoringSmt:: create harmonizing variants" ].stop ();
232
+ timers[" ColoringSmt::2 create harmonizing variants" ].stop ();
233
+
234
+ getRoot ()->clearCache ();
240
235
241
236
timers[__FUNCTION__].stop ();
242
237
}
243
238
239
+ template <typename ValueType>
240
+ ColoringSmt<ValueType>::~ColoringSmt () {
241
+ tree.clear ();
242
+ }
243
+
244
244
template <typename ValueType>
245
245
void ColoringSmt<ValueType>::enableStateExploration(storm::models::sparse::NondeterministicModel<ValueType> const & model) {
246
246
this ->state_exploration_enabled = true ;
@@ -530,7 +530,6 @@ std::pair<bool,std::vector<std::vector<uint64_t>>> ColoringSmt<ValueType>::areCh
530
530
}
531
531
}*/
532
532
533
-
534
533
timers[" areChoicesConsistent::1 is scheduler consistent?" ].start ();
535
534
solver.push ();
536
535
getRoot ()->addFamilyEncoding (subfamily,solver);
@@ -543,6 +542,7 @@ std::pair<bool,std::vector<std::vector<uint64_t>>> ColoringSmt<ValueType>::areCh
543
542
for (uint64_t path: state_path_enabled[state]) {
544
543
const char *label = choice_path_label[choice][path].c_str ();
545
544
solver.add (choice_path_expresssion[choice][path], label);
545
+ // Z3_solver_assert_and_track(ctx, solver.operator Z3_solver(), choice_path_expresssion[choice][path], ctx.bool_const(label));
546
546
}
547
547
}
548
548
bool consistent = check ();
@@ -584,6 +584,7 @@ std::pair<bool,std::vector<std::vector<uint64_t>>> ColoringSmt<ValueType>::areCh
584
584
for (uint64_t path: state_path_enabled[state]) {
585
585
const char *label = choice_path_label[choice][path].c_str ();
586
586
solver.add (choice_path_expresssion[choice][path], label);
587
+ // Z3_solver_assert_and_track(ctx, solver.operator Z3_solver(), choice_path_expresssion[choice][path], ctx.bool_const(label));
587
588
}
588
589
consistent = check ();
589
590
}
@@ -603,6 +604,7 @@ std::pair<bool,std::vector<std::vector<uint64_t>>> ColoringSmt<ValueType>::areCh
603
604
for (auto [choice,path]: this ->unsat_core ) {
604
605
const char *label = choice_path_label[choice][path].c_str ();
605
606
solver.add (choice_path_expresssion_harm[choice][path], label);
607
+ // Z3_solver_assert_and_track(ctx, solver.operator Z3_solver(), choice_path_expresssion_harm[choice][path], ctx.bool_const(label));
606
608
}
607
609
608
610
z3::model model (ctx);
0 commit comments