Skip to content

Commit ce373f6

Browse files
committed
Added CAV CEGIS control front-end
Added second CEGIS control front-end for CAV benchmarks.
1 parent 78ab83e commit ce373f6

16 files changed

+227
-208
lines changed

src/cegis/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ SRC = danger/meta/meta_variable_names.cpp danger/facade/danger_runner.cpp danger
4646
jsa/genetic/jsa_source_provider.cpp jsa/genetic/dynamic_jsa_test_runner.cpp jsa/genetic/random_jsa_mutate.cpp \
4747
jsa/genetic/random_jsa_cross.cpp jsa/genetic/jsa_genetic_convert.cpp jsa/genetic/jsa_random.cpp \
4848
jsa/genetic/solution_helper.cpp jsa/genetic/jsa_serialiser.cpp jsa/genetic/jsa_paragon_wrapper.cpp \
49-
control/facade/control_runner.cpp control/learn/rational_solution_configuration.cpp \
49+
control/facade/control_runner.cpp \
50+
control/learn/print_control_solution.cpp \
51+
control/learn/rational_solution_configuration.cpp control/learn/vector_solution_configuration.cpp \
5052
control/preprocessing/control_preprocessing.cpp control/preprocessing/propagate_controller_sizes.cpp \
5153
control/options/control_program.cpp \
5254
control/learn/nondet_solution.cpp \
5355
control/simplify/remove_unused_elements.cpp \
54-
control/verify/control_symex_verify.cpp control/verify/insert_solution.cpp \
56+
control/verify/insert_solution.cpp control/verify/zero_solutions.cpp \
5557
control/value/float_helper.cpp control/value/control_types.cpp \
5658
refactor/environment/instrument_state_vars.cpp \
5759
refactor/instructionset/create_cegis_processor.cpp refactor/instructionset/execute_cegis_program.cpp \

src/cegis/control/facade/control_runner.cpp

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,48 @@
55
#include <cegis/facade/runner_helper.h>
66
#include <cegis/instrument/instrument_var_ops.h>
77
#include <cegis/control/value/control_types.h>
8+
#include <cegis/control/value/control_vector_solution.h>
89
#include <cegis/control/preprocessing/control_preprocessing.h>
910
#include <cegis/control/preprocessing/propagate_controller_sizes.h>
1011
#include <cegis/control/learn/control_symex_learn.h>
1112
#include <cegis/control/learn/rational_solution_configuration.h>
13+
#include <cegis/control/learn/vector_solution_configuration.h>
1214
#include <cegis/control/verify/control_symex_verify.h>
15+
#include <cegis/control/verify/zero_solutions.h>
1316
#include <cegis/control/facade/control_runner.h>
1417

15-
int run_control(optionst &o, messaget::mstreamt &result,
16-
const symbol_tablet &st, const goto_functionst &gf)
18+
// XXX: Debug
19+
#include <iostream>
20+
// XXX: Debug
21+
22+
namespace
23+
{
24+
template<class solution_configt, class zero_solutiont>
25+
int run(optionst &o, messaget::mstreamt &result, const symbol_tablet &st,
26+
const goto_functionst &gf, const zero_solutiont &default_solution)
1727
{
1828
control_preprocessingt prep(st, gf);
1929
const control_programt &program=prep.get_program();
20-
typedef control_symex_learnt<rational_solution_configurationt> control_learnt;
30+
typedef control_symex_learnt<solution_configt> control_learnt;
2131
control_learnt lcfg(program);
22-
const std::function<void(control_solutiont &)> default_solution=
23-
[&st](control_solutiont &solution)
24-
{ if (!solution.a.operands().empty()) return;
25-
const symbol_typet &type=control_solution_type(st);
26-
const source_locationt loc(default_cegis_source_location());
27-
const namespacet ns(st);
28-
null_message_handlert msg;
29-
const exprt zero(zero_initializer(type, loc, ns, msg));
30-
const struct_exprt zero_struct=to_struct_expr(zero);
31-
solution.a=get_a_controller_comp(ns, zero_struct);
32-
solution.b=get_b_controller_comp(ns, zero_struct);
33-
};
34-
cegis_symex_learnt<control_preprocessingt, control_learnt> learn(o,
35-
prep, lcfg, default_solution);
36-
control_symex_verifyt vcfg(program);
37-
cegis_symex_verifyt<control_symex_verifyt> oracle(o, vcfg);
32+
cegis_symex_learnt<control_preprocessingt, control_learnt> learn(o, prep,
33+
lcfg, default_solution);
34+
typedef control_symex_verifyt<typename solution_configt::solutiont> verifyt;
35+
verifyt vcfg(program);
36+
cegis_symex_verifyt<verifyt> oracle(o, vcfg);
3837
return run_cegis_with_statistics_wrapper(result, o, learn, oracle, prep);
3938
}
39+
}
40+
41+
int run_control(optionst &o, messaget::mstreamt &result,
42+
const symbol_tablet &st, const goto_functionst &gf)
43+
{
44+
const bool is_vector_solution=is_vector_solution_config(st);
45+
if (is_vector_solution_config(st))
46+
{
47+
const zero_vector_solutiont def(st);
48+
return run<vector_solution_configurationt>(o, result, st, gf, def);
49+
}
50+
const zero_rational_solutiont def(st);
51+
return run<rational_solution_configurationt>(o, result, st, gf, def);
52+
}

src/cegis/control/learn/control_symex_learn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class control_symex_learnt
2929
public:
3030
typedef control_counterexamplet counterexamplet;
3131
typedef control_counterexamplest counterexamplest;
32-
typedef control_solutiont candidatet;
32+
typedef typename solution_configt::solutiont candidatet;
3333
/**
3434
* @brief
3535
*

src/cegis/control/learn/rational_solution_configuration.cpp

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/cegis/control/learn/rational_solution_configuration.h

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/cegis/control/preprocessing/control_preprocessing.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include <cegis/control/preprocessing/propagate_controller_sizes.h>
88
#include <cegis/control/preprocessing/control_preprocessing.h>
99

10+
// XXX: Debug
11+
#include <iostream>
12+
// XXX: Debug
13+
1014
control_preprocessingt::control_preprocessingt(const symbol_tablet &st,
1115
const goto_functionst &gf) :
1216
control_program(st, gf)
@@ -15,11 +19,12 @@ control_preprocessingt::control_preprocessingt(const symbol_tablet &st,
1519

1620
namespace
1721
{
18-
const char * const excluded_functions[]=
19-
{ "verify_stability_closedloop_using_dslib", "check_stability_closedloop",
20-
"fxp_double_to_fxp", "fxp_to_double", "ft_closedloop_series",
21-
"poly_mult", "poly_sum", "internal_pow", "fxp_check",
22-
"fxp_control_floatt_to_fxp", "main", "validation" };
22+
const char * const excluded_functions[]= {
23+
"verify_stability_closedloop_using_dslib", "check_stability_closedloop",
24+
"fxp_double_to_fxp", "fxp_to_double", "ft_closedloop_series", "poly_mult",
25+
"poly_sum", "internal_pow", "fxp_check", "fxp_control_floatt_to_fxp",
26+
"main", "validation", "double_matrix_multiplication", "double_sub_matrix",
27+
"check_stability" };
2328

2429
bool is_meta(const goto_programt::const_targett pos)
2530
{
@@ -45,6 +50,12 @@ void control_preprocessingt::operator ()()
4550
goto_programt::targetst &locs=control_program.counterexample_locations;
4651
goto_programt &body=get_entry_body(gf);
4752
collect_counterexample_locations(locs, body, is_meta);
53+
// XXX: Debug
54+
for (const goto_programt::const_targett target : locs)
55+
{
56+
std::cout << "<ce>" << target->code.pretty() << "</ce>" << std::endl;
57+
}
58+
// XXX: Debug
4859
propagate_controller_sizes(st, gf);
4960
}
5061

src/cegis/control/preprocessing/propagate_controller_sizes.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,31 @@
66
#include <cegis/cegis-util/program_helper.h>
77
#include <cegis/control/value/control_vars.h>
88

9-
const exprt &get_controller_comp(const namespacet &ns,
10-
const struct_exprt &value, const char * const comp)
9+
namespace
10+
{
11+
template<class struct_exprt_typet, class exprt_typet>
12+
exprt_typet &get_comp(const namespacet &ns, struct_exprt_typet &value,
13+
const char * const comp)
1114
{
1215
const struct_typet &type=to_struct_type(ns.follow(value.type()));
1316
const struct_typet::componentst &comps=type.components();
1417
for (size_t i=0; i < comps.size(); ++i)
1518
if (id2string(comps[i].get_name()) == comp) return value.operands()[i];
1619
assert(!"Solution component not found.");
1720
}
21+
}
22+
23+
const exprt &get_controller_comp(const namespacet &ns,
24+
const struct_exprt &value, const char * const comp)
25+
{
26+
return get_comp<const struct_exprt, const exprt>(ns, value, comp);
27+
}
28+
29+
exprt &get_controller_comp(const namespacet &ns, struct_exprt &value,
30+
const char * const comp)
31+
{
32+
return get_comp<struct_exprt, exprt>(ns, value, comp);
33+
}
1834

1935
const array_exprt &get_a_controller_comp(const namespacet &ns,
2036
const struct_exprt &value)
@@ -30,6 +46,13 @@ const array_exprt &get_b_controller_comp(const namespacet &ns,
3046
get_controller_comp(ns, value, CEGIS_CONTROL_B_MEMBER_NAME));
3147
}
3248

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+
3356
namespace
3457
{
3558
const exprt &get_a_size(const namespacet &ns, const struct_exprt &value)
@@ -79,6 +102,7 @@ class replace_sizes_visitort: public expr_visitort
79102

80103
void propagate_controller_sizes(const symbol_tablet &st, goto_functionst &gf)
81104
{
105+
if (!st.has_symbol(CEGIS_CONTROL_SOLUTION_VAR_NAME)) return;
82106
const symbolt &symbol=st.lookup(CEGIS_CONTROL_SOLUTION_VAR_NAME);
83107
const struct_exprt &controller_value=to_struct_expr(symbol.value);
84108
const namespacet ns(st);

src/cegis/control/preprocessing/propagate_controller_sizes.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ const exprt &get_controller_comp(
2626
const struct_exprt &value,
2727
const char * const comp);
2828

29+
/**
30+
* @brief
31+
*
32+
* @details
33+
*
34+
* @param ns
35+
* @param value
36+
* @param comp
37+
*/
38+
exprt &get_controller_comp(
39+
const namespacet &ns,
40+
struct_exprt &value,
41+
const char * const comp);
42+
2943
/**
3044
* @brief
3145
*
@@ -54,6 +68,20 @@ const array_exprt &get_b_controller_comp(
5468
const namespacet &ns,
5569
const struct_exprt &value);
5670

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+
5785
/**
5886
* @brief
5987
*

src/cegis/control/value/control_types.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ 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)
13+
{
14+
return to_symbol_type(st.lookup(CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME).type);
15+
}
16+
1217
namespace
1318
{
1419
const struct_typet::componentt &get_comp(const symbol_tablet &st,

0 commit comments

Comments
 (0)