Exemplo n.º 1
0
void
SystemParser::createVariables(TiXmlNode *varinfoNode) {
    unsigned int maxIndex = 0;
    int numS = 0;
    int numA = 0;

    // Calculate highest index, number of state variables, number of action variables
    for (TiXmlNode* currentNode = varinfoNode->FirstChild();
         currentNode != NULL;
         currentNode = currentNode->NextSibling()) {
        const unsigned int index = readIntAttribute(currentNode, "index");
        if (index > maxIndex) maxIndex = index;

        const std::string type = readStringAttribute(currentNode, "type");
        if (type == "ps") numS++;
        else if (type == "in") numA++;
    }

    std::vector<int> state_vars;
    std::vector<uint32_t> action_vars;
    std::map<int, int> state_to_next_vars;

    // Gather all
    for (TiXmlNode* currentNode = varinfoNode->FirstChild();
         currentNode != NULL; currentNode = currentNode->NextSibling()) {
        const unsigned int index = readIntAttribute(currentNode, "index");
        const std::string type = readStringAttribute(currentNode, "type");
        if (type == "ps") {
            state_vars.push_back(index);
            state_to_next_vars[index] = readIntAttribute(currentNode, "corr");
        } else if (type == "in") {
            action_vars.push_back(index);
        }
    }

    std::sort(state_vars.begin(), state_vars.end());
    std::sort(action_vars.begin(), action_vars.end());

    std::vector<uint32_t> bdd_state_vars;
    std::vector<uint32_t> bdd_prime_vars;
    std::vector<uint32_t> bdd_action_vars;

    for (int i=0; i < numS; i++) {
        bdd_state_vars.push_back(i*2);
        bdd_prime_vars.push_back(i*2+1);
        var_to_mtbdd[state_vars[i]] = Mtbdd::mtbddVar(i*2);
        var_to_mtbdd[state_to_next_vars[state_vars[i]]] = Mtbdd::mtbddVar(i*2+1);
    }

    for (int i=0; i < numA; i++) {
        bdd_action_vars.push_back(1000000+i);
        var_to_mtbdd[action_vars[i]] = Mtbdd::mtbddVar(1000000+i);
    }

    varS = Bdd::VariablesCube(bdd_state_vars);
    varT = Bdd::VariablesCube(bdd_prime_vars);
    varA = Bdd::VariablesCube(bdd_action_vars);
}
Exemplo n.º 2
0
int getDatasetDims(int _iDatasetId, int *_piRows, int *_piCols)
{
    /*
     * Get dataspace and dimensions of the dataset. This is a
     * two dimensional dataset.
     */
    if (isEmptyDataset(_iDatasetId))
    {
        *_piCols = 0;
        *_piRows = 0;
    }
    else
    {
        *_piRows = readIntAttribute(_iDatasetId, g_SCILAB_CLASS_ROWS);
        *_piCols = readIntAttribute(_iDatasetId, g_SCILAB_CLASS_COLS);
    }
    return 0;
}
Exemplo n.º 3
0
Mtbdd
SystemParser::nodeToMtbdd(const TiXmlNode* node)
{
    // Have we reached a leaf of the (MT)BDD?
    if (hasAttribute(node, "const_value")) {
        if (leaf_type == float_type) {
            return readDoubleAttribute(node, "const_value");
        } else if (leaf_type == simple_fraction_type) {
            return readSimpleFractionAttribute(node, "const_value");
        } else if (leaf_type == mpq_type) {
            return readMPQAttribute(node, "const_value");
        }
    }

    // The node references another node
    if (hasAttribute(node, "node_ref")) {
        const std::map<std::string, Mtbdd>::const_iterator it =
                build_table.find(readStringAttribute(node, "node_ref"));
        assert(it != build_table.end());
        return it->second;
    }

    // Proper internal node
    const TiXmlNode* child = node->FirstChild();

    // Must have internal id and a variable index
    assert(strcmp(child->Value(), "dd_node")==0);
    assert(hasAttribute(child, "id"));
    assert(hasAttribute(child, "index"));

    // Read the attributes of the node
    const std::string id = readStringAttribute(child, "id");
    const unsigned int index = readIntAttribute(child, "index");

    // Get the then-child of the node
    const TiXmlNode* then_node = child->FirstChild();
    assert(then_node != NULL);
    assert(strcmp(then_node->Value(), "dd_then") == 0);
    Mtbdd then_result = nodeToMtbdd(then_node);

    // Get the else-child of the node
    const TiXmlNode* else_node = then_node->NextSibling();
    assert(else_node != NULL);
    assert(strcmp(else_node->Value(), "dd_else") == 0);
    Mtbdd else_result = nodeToMtbdd(else_node);

    const Mtbdd result = var_to_mtbdd[index].Ite(then_result, else_result);

    if (build_table.find(id) != build_table.end()) {
        assert(build_table[id] == result);
    } else {
        build_table[id] = result;
    }

    return result;
}
Exemplo n.º 4
0
int getSparseDimension(int _iDatasetId, int *_piRows, int *_piCols, int *_piNbItem)
{
    int iRet = 0;
    int iDummy = 0;

    //get number of item in the sparse matrix
    getDatasetDims(_iDatasetId, _piRows, _piCols);
    *_piNbItem = readIntAttribute(_iDatasetId, g_SCILAB_CLASS_ITEMS);

    return iRet;
}
Exemplo n.º 5
0
int getListDims(int _iDatasetId, int *_piItems)
{
    /*
     * Get dataspace and dimensions of the dataset. This is a
     * two dimensional dataset.
     */
    if (isEmptyDataset(_iDatasetId))
    {
        *_piItems = 0;
    }
    else
    {
        *_piItems = readIntAttribute(_iDatasetId, g_SCILAB_CLASS_ITEMS);
    }
    return 0;
}
Exemplo n.º 6
0
//---------------------------------------------------------
int ofxXmlSettings::getAttribute(const string& tag, const string& attribute, int defaultValue, int which){
    int value = defaultValue;
	readIntAttribute(tag, attribute, value, which);
	return value;
}
Exemplo n.º 7
0
int getSODFormatAttribute(int _iFile)
{
    return readIntAttribute(_iFile, g_SCILAB_CLASS_SOD_VERSION);
}