void ModulePropertyWindow::updateModule(const char* item, const char* value) { if(!m_pModule) return; // updating modules if(strcmp(item, "Node") == 0) { m_pModule->setHost(value); } else if(strcmp(item,"Stdio") == 0) { m_pModule->setStdio(value); } else if(strcmp(item, "Workdir") == 0) { m_pModule->setWorkDir(value); } else if(strcmp(item, "Prefix") == 0) { m_pModule->setBasePrefix(value); string strPrefix; Application* application = m_pManager->getKnowledgeBase()->getApplication(); if(application) { strPrefix = string(application->getPrefix()) + string(value); for(int j=0; j<m_pModule->outputCount(); j++) { OutputData *output = &m_pModule->getOutputAt(j); for(int i=0; i<application->connectionCount(); i++) { Connection con = application->getConnectionAt(i); string strOldFrom = con.from(); Connection updatedCon = con; if(con.getCorOutputData()) { if(con.getCorOutputData() == output) { string strFrom = strPrefix + string(output->getPort()); updatedCon.setFrom(strFrom.c_str()); m_pManager->getKnowledgeBase()->updateConnectionOfApplication(application, con, updatedCon); // updating arrow's connection ArrowModel* arrow = dynamic_cast<ArrowModel*>(con.getModel()); if(arrow) { arrow->setConnection(updatedCon); // updating excitatory links from other connections Glib::RefPtr<PortArbitratorModel> arbPort = Glib::RefPtr<PortArbitratorModel>::cast_dynamic(arrow->getDestination()); if(arbPort) arbPort->updateExcitation(arrow, strOldFrom.c_str(), strFrom.c_str()); } } } } } for(int j=0; j<m_pModule->inputCount(); j++) { InputData *input = &m_pModule->getInputAt(j); for(int i=0; i<application->connectionCount(); i++) { Connection con = application->getConnectionAt(i); Connection updatedCon = con; if(con.getCorInputData()) { if(con.getCorInputData() == input) { string strTo = strPrefix + string(input->getPort()); updatedCon.setTo(strTo.c_str()); m_pManager->getKnowledgeBase()->updateConnectionOfApplication(application, con, updatedCon); // updating arrow's connection if(dynamic_cast<ArrowModel*>(con.getModel())) dynamic_cast<ArrowModel*>(con.getModel())->setConnection(updatedCon); } } } } // updating module prefix. m_pManager->getKnowledgeBase()->setModulePrefix(m_pModule, strPrefix.c_str(), false); } } else if(strcmp(item, "Parameters") == 0) { m_pModule->setParam(value); } else if(strcmp(item, "Deployer") == 0) { m_pModule->setBroker(value); } }
void ApplicationPropertyWindow::updateApplication(const char* item, const char* value) { if(strcmp(item, "Prefix") == 0) { m_pManager->getKnowledgeBase()->setApplicationPrefix(m_pApplication, value); Application* mainApplication = m_pManager->getKnowledgeBase()->getApplication(); for(int i=0; i<m_pApplication->sucCount(); i++) { Module* module = dynamic_cast<Module*>(m_pApplication->getLinkAt(i).to()); if(module) { for(int j=0; j<module->outputCount(); j++) { OutputData *output = &module->getOutputAt(j); for(int i=0; i<mainApplication->connectionCount(); i++) { Connection con = mainApplication->getConnectionAt(i); string strOldFrom = con.from(); Connection updatedCon = con; if(con.getCorOutputData() && (con.getCorOutputData() == output)) { string strFrom = string(module->getPrefix()) + string(output->getPort()); updatedCon.setFrom(strFrom.c_str()); m_pManager->getKnowledgeBase()->updateConnectionOfApplication(mainApplication, con, updatedCon); // updating arrow's connection ArrowModel* arrow = dynamic_cast<ArrowModel*>(con.getModel()); if(arrow) { arrow->setConnection(updatedCon); // updating excitatory links from other connections Glib::RefPtr<PortArbitratorModel> arbPort = Glib::RefPtr<PortArbitratorModel>::cast_dynamic(arrow->getDestination()); if(arbPort) arbPort->updateExcitation(arrow, strOldFrom.c_str(), strFrom.c_str()); } } } } for(int j=0; j<module->inputCount(); j++) { InputData *input = &module->getInputAt(j); for(int i=0; i<mainApplication->connectionCount(); i++) { Connection con = mainApplication->getConnectionAt(i); Connection updatedCon = con; if(con.getCorInputData() && (con.getCorInputData() == input)) { string strTo = string(module->getPrefix()) + string(input->getPort()); updatedCon.setTo(strTo.c_str()); m_pManager->getKnowledgeBase()->updateConnectionOfApplication(mainApplication, con, updatedCon); // updating arrow's connection if(dynamic_cast<ArrowModel*>(con.getModel())) dynamic_cast<ArrowModel*>(con.getModel())->setConnection(updatedCon); } } } } // end of if(module) } // end of for } }
void ArbitratorPropertyWindow::onCellEdited(const Glib::ustring& path_string, const Glib::ustring& new_text) { if(!m_arbPort) return; Gtk::TreePath path(path_string); //Get the row from the path: Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path); if(iter) { if(m_pAppWindow) m_pAppWindow->setModified(); Gtk::TreeModel::Row row = *iter; //Put the new value in the model: Glib::ustring strName = Glib::ustring(row[m_Columns.m_col_name]); row[m_Columns.m_col_value] = new_text; row[m_Columns.m_col_color_value] = Gdk::Color("#000000"); Arbitrator& arbitrator = m_arbPort->getArbitrator(); string strRule = new_text.c_str(); Application* application = m_pManager->getKnowledgeBase()->getApplication(); ArrowModel* curArrow = m_arbPort->getArrowModel(strName.c_str()); Connection curCon = *curArrow->getConnection(); strRule.erase(std::remove_if(strRule.begin(), strRule.end(), ::isspace), strRule.end()); if(!strRule.size()) { arbitrator.addRule(strName.c_str(), ""); string carrier = curCon.carrier(); // setting bias = 1.0 size_t start = carrier.find("+bs"); if(start != std::string::npos) { size_t end = carrier.find("+", start+1); if(end == std::string::npos) end = carrier.length(); carrier.erase(start, end-start); } carrier += "+bs.10"; // erase excitatory links to this connection std::map<string, string> &rules = arbitrator.getRuleMap(); std::map<string, string>::iterator itr; for(itr=rules.begin(); itr!=rules.end(); itr++) { ArrowModel* arw = m_arbPort->getArrowModel((itr->first).c_str()); if(arw && (arw != curArrow)) setExcitation(arw, curCon.from(), 0); } // updating carrier curCon.setCarrier(carrier.c_str()); m_pManager->getKnowledgeBase()->updateConnectionOfApplication(application, *curArrow->getConnection(), curCon); curArrow->getConnection()->setCarrier(carrier.c_str()); curArrow->setLabel(carrier.c_str()); } else { string oldRule = arbitrator.getRule(strName.c_str()); arbitrator.addRule(strName.c_str(), new_text.c_str()); if(arbitrator.trainWeights(strName.c_str())) { std::map<std::string, double>& alphas = arbitrator.getAlphas(strName.c_str()); double bias = arbitrator.getBias(strName.c_str()); string carrier = curCon.carrier(); // clearing bias size_t start = carrier.find("+bs"); if(start != std::string::npos) { size_t end = carrier.find("+", start+1); if(end == std::string::npos) end = carrier.length(); carrier.erase(start, end-start); } // setting bias char dummy[64]; sprintf(dummy, "+bs.%d", (int)(bias*10)); carrier += dummy; // erase excitatory links to this connection std::map<string, string> &rules = arbitrator.getRuleMap(); std::map<string, string>::iterator jtr; for(jtr=rules.begin(); jtr!=rules.end(); jtr++) { ArrowModel* arw = m_arbPort->getArrowModel((jtr->first).c_str()); if(arw && (arw != curArrow)) setExcitation(arw, curCon.from(), 0); } std::map<std::string, double>::iterator itr; for(itr=alphas.begin(); itr!=alphas.end(); itr++) { ArrowModel* arw = m_arbPort->getArrowModel((itr->first).c_str()); if(arw && (arw != curArrow)) { //printf("excitation : %s to %s , value:%d\n", arw->getConnection()->from(), curCon.from(), (int)(trainer.getAlphas()[i]*10)); setExcitation(arw, curCon.from(), (int)(itr->second*10)); } } // updating carrier curCon.setCarrier(carrier.c_str()); m_pManager->getKnowledgeBase()->updateConnectionOfApplication(application, *curArrow->getConnection(), curCon); curArrow->getConnection()->setCarrier(carrier.c_str()); curArrow->setLabel(carrier.c_str()); } else { arbitrator.addRule(strName.c_str(), oldRule.c_str()); row[m_Columns.m_col_color_value] = Gdk::Color("#FF0000"); } } m_arbPort->setArbitrator(arbitrator); m_arbPort->setErrorMode(!arbitrator.validate()); m_pParent->reportErrors(); /* typedef Gtk::TreeModel::Children type_children; type_children children = rulesRow->children(); Glib::ustring param; m_arbPort->setErrorMode(false); for(type_children::iterator iter = children.begin(); iter != children.end(); ++iter) { Gtk::TreeModel::Row row = *iter; if(row[m_Columns.m_col_color_value] == Gdk::Color("#FF0000")) { m_arbPort->setErrorMode(true); break; } } */ } }