bool RulesXmlHandler::startElement ( const QString & namespaceURI, const QString & localName, const QString & qName, const QXmlAttributes & atts ) { Q_UNUSED( namespaceURI ); Q_UNUSED( localName ); _line++; if( QString::compare( qName, "Rules", Qt::CaseInsensitive ) == 0 ) { return createRootNode( atts ); } if( QString::compare( qName, "Condition", Qt::CaseInsensitive ) == 0 ) { return createConditionNode( atts ); } if( QString::compare( qName, "Action", Qt::CaseInsensitive ) == 0 ) { return createActionNode( atts ); } if( QString::compare( qName, "Storage", Qt::CaseInsensitive ) == 0 ) { return createStorageNode( atts ); } if( QString::compare( qName, "Emotion", Qt::CaseInsensitive ) == 0 ) { return createEmotionNode( atts ); } if( QString::compare( qName, "DataMining", Qt::CaseInsensitive ) == 0 ) { return createDataMiningNode( atts ); } if( QString::compare( qName, "MathOperation", Qt::CaseInsensitive ) == 0 ) { return createMathOperationNode( atts ); } if( QString::compare( qName, "Property", Qt::CaseInsensitive ) == 0 ) { return createPropertyNode( atts ); } if( QString::compare( qName, "Delete", Qt::CaseInsensitive ) == 0 ) { return createDeleteNode( atts ); } if( QString::compare( qName, "ClearMemory", Qt::CaseInsensitive ) == 0 ) { return createClearMemoryNode( atts ); } if( QString::compare( qName, "Random", Qt::CaseInsensitive ) == 0 ) { return createRandomNode( atts ); } qDebug() << "[RulesXmlHandler::startElement] Invalid element" << qName; return false; }
//---------------------------------------------------------------------------- NodePtr create(const SampleVector& samples, unsigned int num_tests) { auto hist_samples = std::make_unique<HistogramType>(samples); std::vector<SampleType> samples_left; std::vector<SampleType> samples_right; float max_info_gain = -0.1f; NodePtr max_node; for (unsigned int i = 0; i < num_tests; ++i) { NodePtr node(createRandomNode(m_log_stream)); samples_left.clear(); samples_right.clear(); //node->setThreshold(samples); node->split(samples, samples_left, samples_right); HistogramType hist_left(samples_left); HistogramType hist_right(samples_right); std::vector<HistogramType*> hist; hist.push_back(&hist_left); hist.push_back(&hist_right); float infoGain = hist_samples->informationGain(hist); *m_log_stream << ": IGain: " << infoGain << " / " << max_info_gain << ";" << i << ": " << samples_left.size() << "," << samples_right.size() << std::endl; if (infoGain > max_info_gain) { max_info_gain = infoGain; max_node = std::move(node); } } max_node->setHistogram(std::move(hist_samples)); return max_node; }
std::vector<Move> Solver::solve() { if (!isStable()) return std::vector<Move>(); for (int r = 0; r < 10; r++) { std::vector<Move> currentNode = createRandomNode(); while (true) { if (score(currentNode) == 0) { return currentNode; } std::vector< std::vector<Move> > l = getNeighbors(currentNode); int nextEval = -INF; std::vector<Move> nextNode = std::vector<Move>(); for (int i = 0; i < (int) l.size(); i++) { if (score(l[i]) > nextEval) { nextNode = l[i]; nextEval = score(l[i]); } } if (nextEval <= score(currentNode)) { if (score(currentNode) > -3 * (int) blocks.size()) { //print(currentNode); return currentNode; } break; } currentNode = nextNode; } } return std::vector<Move>(); }