コード例 #1
0
ファイル: divide_conquer.cpp プロジェクト: baskarang/icnc
// Divide a node into two child nodes if it can be divided
int Divide::execute(const int & t, DivConq_context & c ) const
{
    my_t temp, tempL, tempR;  // hold contents of items
    c.divideItem.get(t, temp);

    if (divideP(temp))  // contents can be divided
    {
        tempL = leftChildContents(temp); 
        tempR = rightChildContents(temp);

        // print some tracing info
        std::ostringstream oss;
        oss << "divide<" << t
            << ">: [" << temp << "<" << t << ">] -> [" 
            << tempL << "<" << leftChildTag(t) << ">], ["
            << tempR << "<" << rightChildTag(t) << ">], <" 
            << leftChildTag(t) << ">, <"
            << rightChildTag(t) << ">"
            << std::endl;
        std::cout << oss.str();

        // Put child items and tags
        c.divideItem.put(leftChildTag(t), tempL); 
        c.divideTag.put(leftChildTag(t)); 
        c.divideItem.put(rightChildTag(t), tempR);
        c.divideTag.put(rightChildTag(t));

    } else {  // contents can not be divided
        // Put conquerItem with current contents
        c.conquerItem.put(t, temp);

        // If the node is a left child, put conquerTag for the parent node
        if (leftChildTagP(t))
        {
            c.conquerTag.put(parentTag(t));

            // print some tracing info
            std::ostringstream oss;
            oss << "divide<" << t << ">: ["
                << temp << "<" << t << ">] -> conquerItem[" 
                << temp << "<" << t << ">], conquerTag<"
                << parentTag(t) << ">"
                << std::endl;
            std::cout << oss.str();
        } else {
            // print some tracing info
            std::ostringstream oss;
            oss << "divide<" << t << ">: ["
                << temp << "<" << t << ">] -> conquerItem[" 
                << temp << "<" << t << ">]"
                << std::endl;
            std::cout << oss.str();
        }
    };
    return CnC::CNC_Success;
}
コード例 #2
0
ファイル: tag.cpp プロジェクト: tytycoon/basket
State* State::nextState(bool cycle /*= true*/)
{
    if (!parentTag())
        return 0;

    List states = parentTag()->states();
    // The tag contains only one state:
    if (states.count() == 1)
        return 0;
    // Find the next state:
    for (List::iterator it = states.begin(); it != states.end(); ++it)
        // Found the current state in the list:
        if (*it == this) {
            // Find the next state:
            State *next = *(++it);
            if (it == states.end())
                return (cycle ? states.first() : 0);
            return next;
        }
    // Should not happens:
    Q_ASSERT(false);
    return 0;
}
コード例 #3
0
ファイル: divide_conquer.cpp プロジェクト: baskarang/icnc
// Combine two child nodes into a parent node
int Conquer::execute(const int & t, DivConq_context & c ) const
{
    my_t tempL, tempR;  // hold contents of items

    c.conquerItem.get(leftChildTag(t), tempL);     
    c.conquerItem.get(rightChildTag(t), tempR); 

    // Put conquerItem with combined contents from its children
    c.conquerItem.put(t, tempL+tempR);

    // If the node is a left child, put conquerTag for the parent node
    if (leftChildTagP(t)) 
    {
        c.conquerTag.put(parentTag(t));

        // print some tracing info
        std::ostringstream oss;
        oss << "conquer<" << t << ">: ["
            << tempL << "<" << leftChildTag(t) << ">], [" 
            << tempR << "<" << rightChildTag(t) << ">] -> [" 
            << tempL+tempR << "<" << t << ">], <"
            << parentTag(t) << ">"
            << std::endl;
        std::cout << oss.str();
    } else {
        // print some tracing info
        std::ostringstream oss;
        oss << "conquer<" << t << ">: ["
            << tempL << "<" << leftChildTag(t) << ">], [" 
            << tempR << "<" << rightChildTag(t) << ">] -> [" 
            << tempL+tempR << "<" << t << ">]"
            << std::endl;
        std::cout << oss.str();
    }
    return CnC::CNC_Success;
}
コード例 #4
0
ファイル: tag.cpp プロジェクト: tytycoon/basket
QString State::fullName()
{
    if (!parentTag() || parentTag()->states().count() == 1)
        return (name().isEmpty() && parentTag() ? parentTag()->name() : name());
    return QString(i18n("%1: %2",parentTag()->name(), name()));
}