Skip to content

Commit 91257d1

Browse files
committed
Fixed CEGIS control benchmark 2
Interface for control benchmark 2 changed. Adapted front-end to new input format.
1 parent f19b41c commit 91257d1

File tree

12 files changed

+61
-64
lines changed

12 files changed

+61
-64
lines changed

regression/cegis/cegis_control_benchmark_02/eigen_charpoly.c

+11-9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const digital_system_state_space _controller=
4848
.nOutputs = NOUTPUTS
4949
};
5050

51+
extern __CPROVER_EIGEN_fixedbvt K_fxp[4][4];
52+
5153

5254
//typedef int __CPROVER_EIGEN_fixedbvt;
5355
#define __CPROVER_EIGEN_MATRIX_SIZE 3u
@@ -164,9 +166,9 @@ void __CPROVER_EIGEN_charpoly(void) {
164166
}
165167

166168
/*void init(void) {
167-
_controller.K[0][0] = nondet_double();
168-
_controller.K[0][1] = nondet_double();
169-
_controller.K[0][2] = nondet_double();
169+
K_fxp[0][0] = nondet_double();
170+
K_fxp[0][1] = nondet_double();
171+
K_fxp[0][2] = nondet_double();
170172
}*/
171173

172174
__CPROVER_EIGEN_fixedbvt __CPROVER_EIGEN_matrix_multiplication_result[4][4];
@@ -197,7 +199,7 @@ void double_matrix_multiplication(void/* unsigned int i1, unsigned int j1, unsig
197199
//unsigned int __mm_j2;
198200
#define __mm_m1 _controller.B
199201
//__CPROVER_EIGEN_fixedbvt __mm_m1[4][4];
200-
#define __mm_m2 _controller.K
202+
#define __mm_m2 K_fxp
201203
//__CPROVER_EIGEN_fixedbvt __mm_m2[4][4];
202204
#define __mm_m3 __CPROVER_EIGEN_matrix_multiplication_result
203205
//__CPROVER_EIGEN_fixedbvt __mm_m3[4][4];
@@ -248,7 +250,7 @@ void closed_loop(void)
248250
NINPUTS,
249251
NSTATES,
250252
_controller.B,
251-
_controller.K,
253+
K_fxp,
252254
result1);*/
253255
double_matrix_multiplication();
254256

@@ -271,7 +273,7 @@ void closed_loop(void)
271273
_controller.nInputs,
272274
_controller.nStates,
273275
_controller.D,
274-
_controller.K,
276+
K_fxp,
275277
result1);
276278
277279
double_sub_matrix(
@@ -288,9 +290,9 @@ int main(void) {
288290
__CPROVER_EIGEN_charpoly();
289291
//__CPROVER_assert(check_stability(), "");
290292
__CPROVER_assume(check_stability() == 0);
291-
__CPROVER_EIGEN_fixedbvt __trace_K0 = _controller.K[0][0];
292-
__CPROVER_EIGEN_fixedbvt __trace_K1 = _controller.K[0][1];
293-
__CPROVER_EIGEN_fixedbvt __trace_K2 = _controller.K[0][2];
293+
__CPROVER_EIGEN_fixedbvt __trace_K0 = K_fxp[0][0];
294+
__CPROVER_EIGEN_fixedbvt __trace_K1 = K_fxp[0][1];
295+
__CPROVER_EIGEN_fixedbvt __trace_K2 = K_fxp[0][2];
294296
__CPROVER_EIGEN_fixedbvt counterexample_var;
295297
__CPROVER_assume(0.0 <= counterexample_var && counterexample_var <= 10.0);
296298
__CPROVER_assert(__trace_K0 > counterexample_var, "");

regression/cegis/cegis_control_benchmark_03/safety_stability.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ void closed_loop(void)
231231

232232
void inputs_equal_ref_minus_k_times_states(void)
233233
{
234-
__controller_typet states_fxp[NSTATES];
234+
__controller_typet states_fxp[NSTATES] = { 0.0 };
235235
//single input
236236
__controller_typet result_fxp=zero_type;
237237

@@ -453,7 +453,7 @@ int safety_stability(void) {
453453
#endif
454454

455455
#ifdef CPROVER
456-
__controller_typet K_fxp_trace[NSTATES];
456+
__controller_typet K_fxp_trace[NSTATES] = { 0.0 };
457457
__CPROVER_array_copy(K_fxp_trace, K_fxp);
458458
__CPROVER_assert(0 == 1, "");
459459
#endif

src/cegis/control/facade/control_runner.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
#include <cegis/control/verify/zero_solutions.h>
1616
#include <cegis/control/facade/control_runner.h>
1717

18-
// XXX: Debug
19-
#include <iostream>
20-
// XXX: Debug
21-
2218
namespace
2319
{
2420
template<class solution_configt, class zero_solutiont>

src/cegis/control/learn/vector_solution_configuration.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,19 @@ bool is_solution(const goto_trace_stept &step)
2323
return CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME == id;
2424
}
2525

26-
const struct_exprt &find_solution(const goto_tracet &trace)
26+
const array_exprt &find_solution(const goto_tracet &trace)
2727
{
2828
const goto_tracet::stepst &steps=trace.steps;
2929
const auto it=std::find_if(steps.begin(), steps.end(), is_solution);
3030
assert(steps.end() != it);
31-
return to_struct_expr(it->full_lhs_value);
31+
return to_array_expr(it->full_lhs_value);
3232
}
3333
}
3434

3535
void vector_solution_configurationt::convert(solutiont &current_candidate,
3636
const goto_tracet &trace, const symbol_tablet &st)
3737
{
38-
const namespacet ns(st);
39-
const struct_exprt &value=find_solution(trace);
40-
current_candidate.K=get_K_controller_comp(ns, value);
38+
current_candidate.K=find_solution(trace);
4139
}
4240

4341
void vector_solution_configurationt::show_candidate(messaget::mstreamt &os,

src/cegis/control/preprocessing/control_preprocessing.cpp

+35-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1+
#include <util/cprover_prefix.h>
2+
13
#include <cegis/cegis-util/string_helper.h>
24
#include <cegis/cegis-util/inline_user_program.h>
35
#include <cegis/cegis-util/counterexample_vars.h>
46
#include <cegis/cegis-util/program_helper.h>
7+
#include <cegis/instrument/literals.h>
58
#include <cegis/control/value/control_vars.h>
69
#include <cegis/control/simplify/remove_unused_elements.h>
710
#include <cegis/control/preprocessing/propagate_controller_sizes.h>
811
#include <cegis/control/preprocessing/control_preprocessing.h>
12+
#include <goto-programs/remove_returns.h>
913

1014
// XXX: Debug
1115
#include <iostream>
1216
// XXX: Debug
1317

18+
#define TMP_MARKER "$tmp"
19+
1420
control_preprocessingt::control_preprocessingt(const symbol_tablet &st,
1521
const goto_functionst &gf) :
1622
control_program(st, gf)
@@ -33,11 +39,34 @@ bool is_meta(const goto_programt::const_targett pos)
3339
const std::string &func=id2string(loc.get_function());
3440
for (const char * const excluded : excluded_functions)
3541
if (contains(func, excluded)) return true;
36-
if (goto_program_instruction_typet::ASSIGN != pos->type) return false;
37-
const exprt &lhs=to_code_assign(pos->code).lhs();
38-
if (ID_symbol != lhs.id()) return false;
39-
const std::string &var=id2string(to_symbol_expr(lhs).get_identifier());
40-
return CEGIS_CONTROL_SOLUTION_VAR_NAME == var;
42+
if (goto_program_instruction_typet::ASSIGN != pos->type
43+
&& goto_program_instruction_typet::DECL != pos->type) return false;
44+
const std::string &var=id2string(get_affected_variable(*pos));
45+
if (contains(var, TMP_MARKER) || contains(var, RETURN_VALUE_SUFFIX)
46+
|| contains(var, CPROVER_PREFIX)) return true;
47+
return CEGIS_CONTROL_SOLUTION_VAR_NAME == var
48+
|| CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME == var;
49+
}
50+
51+
void add_explicit_nondet_for_extern_vars(goto_programt::targetst &locs,
52+
const symbol_tablet &st, goto_functionst &gf)
53+
{
54+
goto_programt &entry_body=get_body(gf, CPROVER_INIT);
55+
goto_programt::instructionst &instrs=entry_body.instructions;
56+
goto_programt::targett pos=std::prev(instrs.end(), 1);
57+
for (const symbol_tablet::symbolst::value_type &id_and_symbol : st.symbols)
58+
{
59+
const symbolt &symbol=id_and_symbol.second;
60+
if (!symbol.is_extern) continue;
61+
const source_locationt &loc=pos->source_location;
62+
pos=entry_body.insert_before(pos);
63+
pos->source_location=loc;
64+
pos->type=goto_program_instruction_typet::ASSIGN;
65+
const side_effect_expr_nondett rhs(symbol.type);
66+
pos->code=code_assignt(symbol.symbol_expr(), rhs);
67+
}
68+
entry_body.update();
69+
collect_counterexample_locations(locs, entry_body, is_meta, locs.size());
4170
}
4271
}
4372

@@ -50,6 +79,7 @@ void control_preprocessingt::operator ()()
5079
goto_programt::targetst &locs=control_program.counterexample_locations;
5180
goto_programt &body=get_entry_body(gf);
5281
collect_counterexample_locations(locs, body, is_meta);
82+
add_explicit_nondet_for_extern_vars(locs, st, gf);
5383
// XXX: Debug
5484
for (const goto_programt::const_targett target : locs)
5585
{

src/cegis/control/preprocessing/propagate_controller_sizes.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ const array_exprt &get_b_controller_comp(const namespacet &ns,
4646
get_controller_comp(ns, value, CEGIS_CONTROL_B_MEMBER_NAME));
4747
}
4848

49-
const array_exprt &get_K_controller_comp(const namespacet &ns,
50-
const struct_exprt &value)
51-
{
52-
return to_array_expr(
53-
get_controller_comp(ns, value, CEGIS_CONTROL_K_MEMBER_NAME));
54-
}
55-
5649
namespace
5750
{
5851
const exprt &get_a_size(const namespacet &ns, const struct_exprt &value)

src/cegis/control/preprocessing/propagate_controller_sizes.h

-14
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,6 @@ const array_exprt &get_b_controller_comp(
6868
const namespacet &ns,
6969
const struct_exprt &value);
7070

71-
/**
72-
* @brief
73-
*
74-
* @details
75-
*
76-
* @param ns
77-
* @param value
78-
*
79-
* @return
80-
*/
81-
const array_exprt &get_K_controller_comp(
82-
const namespacet &ns,
83-
const struct_exprt &value);
84-
8571
/**
8672
* @brief
8773
*

src/cegis/control/value/control_types.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ const symbol_typet &control_solution_type(const symbol_tablet &st)
99
return to_symbol_type(st.lookup(CEGIS_CONTROL_SOLUTION_VAR_NAME).type);
1010
}
1111

12-
const symbol_typet &control_vector_solution_type(const symbol_tablet &st)
12+
const array_typet &control_vector_solution_type(const symbol_tablet &st)
1313
{
14-
return to_symbol_type(st.lookup(CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME).type);
14+
return to_array_type(st.lookup(CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME).type);
1515
}
1616

1717
namespace

src/cegis/control/value/control_types.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const class symbol_typet &control_solution_type(const class symbol_tablet &st);
3030
*
3131
* @return
3232
*/
33-
const class symbol_typet &control_vector_solution_type(const class symbol_tablet &st);
33+
const class array_typet &control_vector_solution_type(const class symbol_tablet &st);
3434

3535
/**
3636
* @brief

src/cegis/control/value/control_vars.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define CPROVER_CEGIS_CONTROL_VALUE_CONTROL_VARS_H
1212

1313
#define CEGIS_CONTROL_SOLUTION_VAR_NAME "controller"
14-
#define CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME "_controller"
14+
#define CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME "K_fxp"
1515
#define __CEGIS_ALTERNATIVE_MEMBER_NAMES
1616
#ifndef __CEGIS_ALTERNATIVE_MEMBER_NAMES
1717
#define CEGIS_CONTROL_A_MEMBER_NAME "a"
@@ -21,7 +21,6 @@
2121
#else
2222
#define CEGIS_CONTROL_A_MEMBER_NAME "den"
2323
#define CEGIS_CONTROL_B_MEMBER_NAME "num"
24-
#define CEGIS_CONTROL_K_MEMBER_NAME "K"
2524
#define CEGIS_CONTROL_A_SIZE_MEMBER_NAME "den_size"
2625
#define CEGIS_CONTROL_B_SIZE_MEMBER_NAME "num_size"
2726
#endif

src/cegis/control/verify/insert_solution.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,5 @@ void insert_solution(control_programt &program,
9696
const is_assignment_tot pred(CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME);
9797
const goto_programt::targett it=std::find_if(instrs.begin(), end, pred);
9898
assert(end != it);
99-
struct_exprt &value=to_struct_expr(to_code_assign(it->code).rhs());
100-
const namespacet ns(program.st);
101-
exprt &k=get_controller_comp(ns, value, CEGIS_CONTROL_K_MEMBER_NAME);
102-
k=solution.K;
99+
to_code_assign(it->code).rhs()=solution.K;
103100
}

src/cegis/control/verify/zero_solutions.cpp

+5-9
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@
1010

1111
bool is_vector_solution_config(const symbol_tablet &st)
1212
{
13-
if (!st.has_symbol(CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME)) return false;
14-
const typet &type=st.lookup(CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME).type;
15-
const typet &resolved=namespacet(st).follow(type);
16-
if (ID_struct != resolved.id()) return false;
17-
const struct_typet &struct_type=to_struct_type(resolved);
18-
return struct_type.has_component(CEGIS_CONTROL_K_MEMBER_NAME);
13+
return st.has_symbol(CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME);
1914
}
2015

2116
zero_rational_solutiont::zero_rational_solutiont(const symbol_tablet &st) :
@@ -52,8 +47,9 @@ void zero_vector_solutiont::operator ()(
5247
control_vector_solutiont &solution) const
5348
{
5449
if (!solution.K.operands().empty()) return;
55-
const symbol_typet &type=control_vector_solution_type(st);
5650
const namespacet ns(st);
57-
const struct_exprt zero_struct=make_zero(ns, type);
58-
solution.K=get_K_controller_comp(ns, zero_struct);
51+
const array_typet &type=control_vector_solution_type(st);
52+
const source_locationt loc(default_cegis_source_location());
53+
null_message_handlert msg;
54+
solution.K=to_array_expr(zero_initializer(type, loc, ns, msg));
5955
}

0 commit comments

Comments
 (0)