int main(int argc, char **argv) { Air_Conditioner_Controller acc; struct sml_variable *temp, *presence, *power; struct sml_object *sml; _initialize_acc(&acc); if (argc != 2) { fprintf(stderr, "Usage: %s <engine_type (0 fuzzy, 1 ann)>\n", argv[0]); fprintf(stderr, "Fuzzy Test: %s 0\n", argv[0]); fprintf(stderr, "Ann Test: %s 1\n", argv[0]); return -1; } sml = _sml_new(atoi(argv[1])); if (!sml) { sml_critical("Failed to create sml"); return -1; } sml_main_loop_init(); //Set stabilization hits and initial required obs to a low value because //this is a simulation and we don't want to wait for a long time before //getting interesting results sml_set_stabilization_hits(sml, STABILIZATION_HITS); sml_ann_set_initial_required_observations(sml, INITIAL_REQUIRED_OBS); //Create temperature input temp = sml_new_input(sml, "Temperature"); sml_variable_set_range(sml, temp, 0, 48); sml_fuzzy_variable_set_default_term_width(sml, temp, 16); //Create presence input presence = sml_new_input(sml, "Presence"); sml_variable_set_range(sml, presence, 0, 1); sml_fuzzy_variable_set_default_term_width(sml, presence, 0.5); //Create power output power = sml_new_output(sml, "Power"); sml_variable_set_range(sml, power, 0, 3); sml_fuzzy_variable_set_default_term_width(sml, power, 1); sml_fuzzy_variable_set_is_id(sml, power, true); //set SML callbacks sml_set_read_state_callback(sml, _read_state_cb, &acc); sml_main_loop_schedule_sml_process(sml, READ_TIMEOUT); sml_set_output_state_changed_callback(sml, _output_state_changed_cb, &acc); sml_main_loop_run(); sml_free(sml); sml_main_loop_shutdown(); return 0; }
static struct sml_variable * _create_input(Context *ctx, const char *name) { struct sml_variable *v; v = sml_new_input(ctx->sml, name); sml_variable_set_range(ctx->sml, v, 0, ctx->num_players - 1); sml_fuzzy_variable_set_default_term_width(ctx->sml, v, 1); sml_fuzzy_variable_set_is_id(ctx->sml, v, true); return v; }
static bool _initialize_sml(Context *ctx) { sml_set_stabilization_hits(ctx->sml, 0); sml_set_read_state_callback(ctx->sml, _read_state_cb, ctx); if (ctx->sml_engine == ANN_ENGINE) sml_ann_set_initial_required_observations(ctx->sml, REQUIRED_OBS); ctx->offense1 = _create_input(ctx, "red_striker"); ctx->defense1 = _create_input(ctx, "red_goalkeeper"); ctx->offense2 = _create_input(ctx, "yellow_striker"); ctx->defense2 = _create_input(ctx, "yellow_goalkeeper"); //number of the winner team ctx->winner = sml_new_output(ctx->sml, "winner"); sml_variable_set_range(ctx->sml, ctx->winner, 0, 2); sml_fuzzy_variable_set_default_term_width(ctx->sml, ctx->winner, 1); sml_fuzzy_variable_set_is_id(ctx->sml, ctx->winner, true); return true; }