Skip to content

Commit 4132774

Browse files
committed
Adapted CEGIS control vector front-end
Adapted CEGIS control front-end for state space solutions to new vector solution input format. Adapted respective regression test 3 testing this behaviour.
1 parent f75d1e0 commit 4132774

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

regression/cegis/cegis_control_benchmark_03/safety_stability.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
#include "operators.h"
99

1010
#ifdef CPROVER
11-
#define __DSVERIFIER_assert(x) __CPROVER_assume(x)
11+
//#define __DSVERIFIER_assert(x) __CPROVER_assume(x)
12+
#define __DSVERIFIER_assert(x) __CPROVER_assert(x, "")
1213
#else
1314
#include <assert.h>
1415
#define __DSVERIFIER_assert(x) assert(x)
@@ -441,6 +442,14 @@ void assume_corner_cases_for_states(void) {
441442
#endif
442443
#endif
443444

445+
void assert_nonzero_controller(void) {
446+
int nonzero_coefficients=0;
447+
for (int i = 0; i < NSTATES; ++i) {
448+
if (K_fxp[i] != controller_cast(0.0)) ++nonzero_coefficients;
449+
}
450+
__DSVERIFIER_assert(nonzero_coefficients > 0);
451+
}
452+
444453
int safety_stability(void) {
445454
#ifdef INTERVAL
446455
get_bounds(); //get interval bounds
@@ -453,9 +462,9 @@ int safety_stability(void) {
453462
#endif
454463

455464
#ifdef CPROVER
456-
__controller_typet K_fxp_trace[NSTATES] = { 0.0 };
465+
__controller_typet K_fxp_trace[NSTATES] = { controller_cast(0.0) };
457466
__CPROVER_array_copy(K_fxp_trace, K_fxp);
458-
__CPROVER_assert(0 == 1, "");
467+
//__CPROVER_assert(0 == 1, "");
459468
#endif
460469

461470
return 0;
@@ -470,6 +479,7 @@ int main(void) {
470479
_controller_states[stateIndex] = _state_poles[poleIndex][poleIndex];
471480
}
472481
#endif
482+
assert_nonzero_controller();
473483
safety_stability();
474484
#ifndef CPROVER
475485
}

src/cegis/control/preprocessing/control_preprocessing.cpp

+14-7
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,29 @@ bool is_meta(const goto_programt::const_targett pos)
5454
void add_explicit_nondet_for_extern_vars(goto_programt::targetst &locs,
5555
const symbol_tablet &st, goto_functionst &gf)
5656
{
57-
goto_programt &entry_body=get_body(gf, CPROVER_INIT);
58-
goto_programt::instructionst &instrs=entry_body.instructions;
59-
goto_programt::targett pos=std::prev(instrs.end(), 1);
57+
goto_programt &entry_body=get_entry_body(gf);
58+
goto_programt &init_body=get_body(gf, CPROVER_INIT);
59+
goto_programt::targett entry_pos=entry_body.instructions.begin();
60+
goto_programt::targett init_pos=std::prev(init_body.instructions.end(), 1);
61+
size_t marker_index=locs.size();
6062
for (const symbol_tablet::symbolst::value_type &id_and_symbol : st.symbols)
6163
{
6264
const symbolt &symbol=id_and_symbol.second;
63-
if (!symbol.is_extern) continue;
65+
const std::string &name=id2string(id_and_symbol.first);
66+
if (!symbol.is_extern || contains(name, CPROVER_PREFIX)) continue;
67+
const bool is_solution_var=CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME == name
68+
|| CEGIS_CONTROL_SOLUTION_VAR_NAME == name;
69+
goto_programt &body=is_solution_var ? init_body : entry_body;
70+
goto_programt::targett &pos=is_solution_var ? init_pos : entry_pos;
6471
const source_locationt &loc=pos->source_location;
65-
pos=entry_body.insert_before(pos);
72+
if (is_solution_var) pos=body.insert_before(pos);
73+
else pos=body.insert_after(pos);
6674
pos->source_location=loc;
6775
pos->type=goto_program_instruction_typet::ASSIGN;
6876
const side_effect_expr_nondett rhs(symbol.type);
6977
pos->code=code_assignt(symbol.symbol_expr(), rhs);
7078
}
7179
entry_body.update();
72-
collect_counterexample_locations(locs, entry_body, is_meta, locs.size());
7380
}
7481
}
7582

@@ -81,8 +88,8 @@ void control_preprocessingt::operator ()()
8188
inline_user_program(st, gf);
8289
goto_programt::targetst &locs=control_program.counterexample_locations;
8390
goto_programt &body=get_entry_body(gf);
84-
collect_counterexample_locations(locs, body, is_meta);
8591
add_explicit_nondet_for_extern_vars(locs, st, gf);
92+
collect_counterexample_locations(locs, body, is_meta);
8693
// XXX: Debug
8794
for (const goto_programt::const_targett target : locs)
8895
{

0 commit comments

Comments
 (0)