Beispiel #1
0
void
VariableSet::changeHand(const Hand *h, bool sticky)
{
	if (sticky) {
		assert(mHand->getNumDOF() == h->getNumDOF());
		assert(mHand->getEigenGrasps()->getSize() == h->getEigenGrasps()->getSize());
	}
	mHand = h;
	if (!sticky) {
		clearVariables();
		createVariables();
	}
}
Beispiel #2
0
SystemParser::SystemParser(const char* filename, unsigned int verbosity, LeafType leaf_type)
{
    // Open the document
    TiXmlDocument document = TiXmlDocument(filename);
    if (!document.LoadFile()) {
        throw ParseError("[ERROR] Could not load the input file.");
    }

    // Get the root node of the XML-document
    TiXmlNode* rootNode = document.RootElement();
    if (rootNode == NULL) {
        throw ParseError("[ERROR] Could not access the root node of the XML-tree");
    }

    // Find out the type of the transition system (lts, ctmc, imc)
    const std::string type_str = readStringAttribute(rootNode, "type");
    if (type_str == "lts") system_type = lts_type;
    else if (type_str == "ctmc") system_type = ctmc_type;
    else if (type_str == "imc") system_type = imc_type;
    else system_type = lts_type;

    this->leaf_type = leaf_type;

    // Traverse the children of the root node and collect the pointers to the parts we need.
    TiXmlNode* varinfoNode = NULL;
    TiXmlNode* initialstateNode = NULL;
    TiXmlNode* transNode = NULL;
    TiXmlNode* markovtransNode = NULL;
    TiXmlNode* initialpartitionNode = NULL;
    TiXmlNode* tauNode = NULL;

    for (TiXmlNode* currentNode = rootNode->FirstChild();
         currentNode != NULL;
         currentNode = currentNode->NextSibling()) {

        if (currentNode->ToElement() == NULL) continue;

        const char* const name = currentNode->ToElement()->Value();

        if (strcmp(name, "variables") == 0) {
            varinfoNode = currentNode;
        } else if (strcmp(name, "dd") == 0) {
            std::string bdd_type = readStringAttribute(currentNode, "type");
            if (bdd_type == "initial_state") {
                initialstateNode = currentNode;
            } else if (bdd_type == "trans") {
                transNode = currentNode;
            } else if (bdd_type == "markov_trans") {
                markovtransNode = currentNode;
            } else if (bdd_type == "tau") {
                tauNode = currentNode;
            }
        } else if (strcmp(name, "initial_partition") == 0) {
            initialpartitionNode = currentNode;
        }
    }

    // Check if we have found the variable information
    if (varinfoNode == NULL) {
        throw ParseError("[ERROR] No variable information found!");
    }

    // Check if the correct information exists for the system type
    switch (system_type) {
    case lts_type:
        if (markovtransNode != NULL) {
            throw ParseError("[ERROR] LTS must not have any Markov transitions!");
        }
        if (transNode == NULL) {
            throw ParseError("[ERROR] LTS must have an interactive transition relation!");
        }
        break;
    case ctmc_type:
        if (transNode != NULL) {
            throw ParseError("[ERROR] CTMCs must not have any interactive transitions!");
        }
        if (markovtransNode == NULL) {
            throw ParseError("[ERROR] CTMCs must have a Markov transition relation!");
        }
        break;
    case imc_type:
        if (transNode == NULL) {
            throw ParseError("[ERROR] IMCs must have an interactive transition relation!");
        }
        if (markovtransNode == NULL) {
            throw ParseError("[ERROR] IMCs must have a Markov transition relation!");
        }
        break;
    }

        // Parse the variable information and create the BDD variables
        // together with an appropriate order for refinement
        if (verbosity > 0) std::cout << "[INFO] Creating BDD variables ... " << std::flush;
        createVariables(varinfoNode);
        if (verbosity > 0) std::cout << "finished." << std::endl;

        // Build the BDDs/ADDs for all parts
        if (verbosity > 0) std::cout << "[INFO] Building BDDs ... " << std::flush;

        std::vector<std::pair<Bdd, Bdd>> transitions;
        Bdd _transitions = Bdd::bddZero();
        if (transNode != NULL) {
            _transitions = nodeToBdd(transNode);
            transitions.push_back(std::make_pair(_transitions, varS * varT));
        }

        Mtbdd markov_transitions;
        if (markovtransNode != NULL) markov_transitions = nodeToMtbdd(markovtransNode);

        Bdd tau;
        if (tauNode != NULL) tau = nodeToBdd(tauNode);
        else {
            // Default value of tau: 0
            int action_bits = sylvan_set_count(varA.GetBDD());
            std::vector<uint8_t> tau_value;
            for (int i=0; i<action_bits; i++) tau_value.push_back(0);
            tau = Bdd::bddCube(varA, tau_value);
        }

        Bdd initial_state;
        if (initialstateNode != NULL) initial_state = nodeToBdd(initialstateNode);

        Bdd states = computeStateSpace(_transitions, markov_transitions);

        std::vector<Bdd> initial_partition;
        if (initialpartitionNode != NULL) {
            for (TiXmlNode* currentNode = initialpartitionNode->FirstChild();
                 currentNode != NULL; currentNode = currentNode->NextSibling()) {
                initial_partition.push_back(nodeToBdd(currentNode));
            }
        }
        if (initial_partition.size() == 0) initial_partition.push_back(states);
        if (verbosity > 0) std::cout << "finished." << std::endl;

        // Fill the right system with information
        switch (system_type) {
        case lts_type:
            lts.transitions = transitions;
            lts.states = states;
            lts.tau = tau;
            lts.initialStates = initial_state;
            lts.initialPartition = initial_partition;
            lts.varS = varS;
            lts.varT = varT;
            lts.varA = varA;
            break;

        case imc_type:
            imc.transitions = transitions;
            imc.markov_transitions = markov_transitions;
            imc.states = states;
            imc.tau = tau;
            imc.initialStates = initial_state;
            imc.initialPartition = initial_partition;
            imc.varS = varS;
            imc.varT = varT;
            imc.varA = varA;
            break;

        case ctmc_type:
            ctmc.markov_transitions = markov_transitions;
            ctmc.states = states;
            ctmc.initialStates = initial_state;
            ctmc.initialPartition = initial_partition;
            ctmc.varS = varS;
            ctmc.varT = varT;
            break;

        default:
            break;
        }
}