コード例 #1
0
ファイル: peterson.c プロジェクト: alex-ren/MTVeri
// State: (PC0:int, PC1:int, turn:int, flags:array)
// while (flag[1] && turn == 1)
int pg_transition_p0_2(model_t model, int*src,TransitionCB callback,void*user_context) {
    int dst[state_length()]; // the next state values
    // not all variables are modified so copy the source state
    memcpy(dst, src, sizeof(int) * state_length()); 

    int turn = src[2];

    // get the chunk
    int index = src[3];
    chunk res=GBchunkGet(model, char_array_type, index);
    char *flags_old = res.data;

    // action
    int action[1];
    action[0] = action0_index;
    transition_info_t transition_info = { action, 0 };

    //
    if (1 == flags_old[1] && 1 == turn)
    {
        // do nothing, state is the same
        int cpy[4] = {0,0,0,0}; // provide modified variables
        callback(user_context, &transition_info, dst, cpy);
        return 1; // return number of successors
    }
    else {
        dst[0] = CRITICAL_SEG;  // PC0 = CRITICAL_SEG
        int cpy[4] = {1,0,0,0}; // provide modified variables
        callback(user_context, &transition_info, dst, cpy);
        return 1; // return number of successors
    }
}
コード例 #2
0
ファイル: peterson.c プロジェクト: alex-ren/MTVeri
// State: (PC0:int, PC1:int, turn:int, flags:array)
// flag[0] = true;
int pg_transition_p0_0(model_t model, int*src,TransitionCB callback,void*user_context) {
    int dst[state_length()]; // the next state values
    // not all variables are modified so copy the source state
    memcpy(dst, src, sizeof(int) * state_length()); 

    dst[0] = 1;  // PC0 = 1

    // set the chunk
    int index = src[3];
    chunk res=GBchunkGet(model, char_array_type, index);
    char *flags_old = res.data;

    char flags[2] = {};
    flags[0] = 1;
    flags[1] = flags_old[1];
    index = GBchunkPut(model, char_array_type, chunk_ld(2, flags));
    dst[3] = index;

    int action[1];
    action[0] = action0_index;
    transition_info_t transition_info = { action, 0 };

    int cpy[4] = {1,0,0,1}; // provide modified variables
    callback(user_context, &transition_info, dst, cpy);
    return 1; // return number of successors
}
コード例 #3
0
ファイル: peterson.c プロジェクト: alex-ren/MTVeri
// State: (PC0:int, PC1:int, turn:int, flags:array)
// turn = 1;
int pg_transition_p0_1(model_t model, int*src,TransitionCB callback,void*user_context) {
    int dst[state_length()]; // the next state values
    // not all variables are modified so copy the source state
    memcpy(dst, src, sizeof(int) * state_length()); 

    dst[0] = 2;  // update PC0
    dst[2] = 1;  // turn = 1

    int action[1];
    action[0] = action0_index;
    transition_info_t transition_info = { action, 0 };

    int cpy[4] = {1,0,1,0}; // provide modified variables
    callback(user_context, &transition_info, dst, cpy);
    return 1; // return number of successors
}
コード例 #4
0
ファイル: dlopen-impl.c プロジェクト: maritaria/LtsMin-Games
void pins_model_init(model_t m) {

    // create the LTS type LTSmin will generate
    lts_type_t ltstype=lts_type_create();

    // set the length of the state
    lts_type_set_state_length(ltstype, state_length());

    // add an "int" type for a state slot
    int int_type = lts_type_add_type(ltstype, "int", NULL);
    lts_type_set_format (ltstype, int_type, LTStypeDirect);

    // add an "action" type for edge labels
    int action_type = lts_type_add_type(ltstype, "action", NULL);
    lts_type_set_format (ltstype, action_type, LTStypeEnum);

    // add a "bool" type for state labels
    int bool_type = lts_type_add_type (ltstype, LTSMIN_TYPE_BOOL, NULL);
    lts_type_set_format(ltstype, bool_type, LTStypeEnum);

    // set state name & type
    for (int i=0; i < state_length(); ++i) {
        char name[3]; sprintf(name, "%d", i);
        lts_type_set_state_name(ltstype,i,name);
        lts_type_set_state_typeno(ltstype,i,int_type);
    }

    // edge label types
    lts_type_set_edge_label_count (ltstype, 1);
    lts_type_set_edge_label_name(ltstype, 0, "action");
    lts_type_set_edge_label_type(ltstype, 0, "action");
    lts_type_set_edge_label_typeno(ltstype, 0, action_type);

    // state label types
    lts_type_set_state_label_count (ltstype, 1);
    lts_type_set_state_label_name (ltstype, 0, "goal");
    lts_type_set_state_label_typeno (ltstype, 0, bool_type);

    // done with ltstype
    lts_type_validate(ltstype);

    // make sure to set the lts-type before anything else in the GB
    GBsetLTStype(m, ltstype);

    // setting all values for all non direct types
    GBchunkPut(m, action_type, chunk_str("switch_a"));
    GBchunkPut(m, action_type, chunk_str("switch_b"));
    GBchunkPut(m, action_type, chunk_str("switch_c"));
    GBchunkPut(m, action_type, chunk_str("switch_d"));
    GBchunkPut(m, action_type, chunk_str("switch_ab"));
    GBchunkPut(m, action_type, chunk_str("switch_ac"));
    GBchunkPut(m, action_type, chunk_str("switch_ad"));
    GBchunkPut(m, action_type, chunk_str("switch_bc"));
    GBchunkPut(m, action_type, chunk_str("switch_bd"));
    GBchunkPut(m, action_type, chunk_str("switch_cd"));
    GBchunkPut(m, bool_type, chunk_str(LTSMIN_VALUE_BOOL_FALSE));
    GBchunkPut(m, bool_type, chunk_str(LTSMIN_VALUE_BOOL_TRUE));

    // set state variable values for initial state
    GBsetInitialState(m, initial_state());

    // set function pointer for the next-state function
    GBsetNextStateLong(m, (next_method_grey_t) next_state);

    // set function pointer for the label evaluation function
    GBsetStateLabelLong(m, (get_label_method_t) state_label);

    // create combined matrix
    matrix_t *cm = malloc(sizeof(matrix_t));
    dm_create(cm, group_count(), state_length());

    // set the read dependency matrix
    matrix_t *rm = malloc(sizeof(matrix_t));
    dm_create(rm, group_count(), state_length());
    for (int i = 0; i < group_count(); i++) {
        for (int j = 0; j < state_length(); j++) {
            if (read_matrix(i)[j]) {
                dm_set(cm, i, j);
                dm_set(rm, i, j);
            }
        }
    }
    GBsetDMInfoRead(m, rm);

    // set the write dependency matrix
    matrix_t *wm = malloc(sizeof(matrix_t));
    dm_create(wm, group_count(), state_length());
    for (int i = 0; i < group_count(); i++) {
        for (int j = 0; j < state_length(); j++) {
            if (write_matrix(i)[j]) {
                dm_set(cm, i, j);
                dm_set(wm, i, j);
            }
        }
    }
    GBsetDMInfoMustWrite(m, wm);

    // set the combined matrix
    GBsetDMInfo(m, cm);

    // set the label dependency matrix
    matrix_t *lm = malloc(sizeof(matrix_t));
    dm_create(lm, label_count(), state_length());
    for (int i = 0; i < label_count(); i++) {
        for (int j = 0; j < state_length(); j++) {
            if (label_matrix(i)[j]) dm_set(lm, i, j);
        }
    }
    GBsetStateLabelInfo(m, lm);

}