void loop(){
	if(!started){ 
		print("Program active\n\n",0); 
		started=true;
	};
	
	for(int i=0;i<11;i++){ // count over LED pairs
		if(i==0) { 
			if(cycleCount < 4){
				cycleCount++;
			} else reInit();	// reinit after 3 incomplete cycles
		};
		if(checkCompletion() == -1 && haltUntilFirstTouch) { i=0;} // stalls the sequence on position 1 until that is touched
		
		print("Pair ",0); print(i,0); print(" is on.\n",0);
		killLEDs();
		lightLEDpair(i);
				  
		for(int j=0;j<25;j++){ // split delays in about 10-20ms to have steady timing			
			if(fridgeUnlocked) unlock();
			
			checkNodes();
			int completedStep = checkSequence();
			
			if((completedStep >= 0) &&
			   (completedStep != previousCycle) &&
			   (touchLEDcorrespondence[completedStep] < i+1)) { // if the LEDs are ahead of the user, restart at the user's current position
			   
			    previousCycle = completedStep;
				i = touchLEDcorrespondence[completedStep];		// it seems if i=0 here the next loop is executed with i=1
				if(i == 0) revertTo0 = true;
				print("Reverted to pair ",0);print(i,0);print("\n",0);
				break;
			}
			previousCycle = completedStep;
			delay((LEDpairs[i][4]/25));
			
		}
		if(revertTo0){
			revertTo0 = false;
			break;	// break main for loop to get i=0
		}
		if(fridgeUnlocked){ 
			print("Successfully unlocked!\n\n",0);
			lightLEDpair(10);
			
			for(int j=0;j<3;j++){
				delay(2500);
				killLEDs();
				delay(1500);
				lightLEDpair(10);
			};
			
			delay(3000); 
			reInit(); 
			break;
		};
	}
}
/*--------------------------------------------------------*/
int AzTree::leafNum() const
{
  checkNodes("leafNum");
  int leaf_num = 0;
  int nx;
  for (nx = 0; nx < nodes_used; ++nx) {
    if (nodes[nx].isLeaf()) {
      ++leaf_num;
    }
  }
  return leaf_num;
}
void
NIImporter_VISUM::parse_EdgePolys() {
    // get the from- & to-node and validate them
    NBNode* from = getNamedNode("VonKnot", "VonKnotNr");
    NBNode* to = getNamedNode("NachKnot", "NachKnotNr");
    if (!checkNodes(from, to)) {
        return;
    }
    bool failed = false;
    int index;
    SUMOReal x, y;
    try {
        index = TplConvert::_2int(myLineParser.get("INDEX").c_str());
        x = getNamedFloat("XKoord");
        y = getNamedFloat("YKoord");
    } catch (NumberFormatException&) {
        WRITE_ERROR("Error in geometry description from node '" + from->getID() + "' to node '" + to->getID() + "'.");
        return;
    }
    Position pos(x, y);
    if (!NILoader::transformCoordinates(pos)) {
        WRITE_ERROR("Unable to project coordinates for node '" + from->getID() + "'.");
        return;
    }
    NBEdge* e = from->getConnectionTo(to);
    if (e != 0) {
        e->addGeometryPoint(index, pos);
    } else {
        failed = true;
    }
    e = to->getConnectionTo(from);
    if (e != 0) {
        e->addGeometryPoint(-index, pos);
        failed = false;
    }
    // check whether the operation has failed
    if (failed) {
        // we should report this to the warning instance only if we have removed
        //  some nodes or edges...
        if (OptionsCont::getOptions().isSet("keep-edges.min-speed") || OptionsCont::getOptions().isSet("keep-edges.explicit")) {
            WRITE_WARNING("Could not set geometry between node '" + from->getID() + "' and node '" + to->getID() + "'.");
        } else {
            // ... in the other case we report this to the error instance
            if (OptionsCont::getOptions().getBool("visum.verbose-warnings")) {
                WRITE_WARNING("There is no edge from node '" + from->getID() + "' to node '" + to->getID() + "'.");
            }
        }
    }
}
示例#4
0
void checkNodes( const std::shared_ptr< spec_reader::SpecNode > specNode, size_t level = 0 )
{
	std::shared_ptr< spec_reader::SpecNode > sn = specNode;
	
	bool end = false;
	while( ! end )
	{
		LOG_INFO( common::details::kColorGreen << std::setw( 3 * level + 2 ) << "* " << sn->getId() << common::details::kColorStd );
		if( sn->isGroup() )
		{
			checkNodes( sn->firstChild(), level + 1 );
		}
		sn = sn->next();
		if( sn == nullptr )
			end = true;
	}
}
/*--------------------------------------------------------*/
void AzTree::clean_up()
{
  checkNodes("clean_up");

  int nx;
  for (nx = 0; nx < nodes_used; ++nx) {
    if (!nodes[nx].isLeaf()) continue;

    /*---  add non-leaf weights to the leaf weight ---*/
    int px = nodes[nx].parent_nx;
    for ( ; ; ) {
      if (px < 0) break;
      nodes[nx].weight += nodes[px].weight;
      px = nodes[px].parent_nx;
    }
  }

  for (nx = 0; nx < nodes_used; ++nx) {
    if (nodes[nx].isLeaf()) continue;
    nodes[nx].weight = 0; /* zero-out non-leaf weights */
  }
}
示例#6
0
文件: trie.cpp 项目: gottcode/tanglet
Trie::Trie(const QHash<QString, QStringList>& words)
{
	TrieGenerator generator(words);
	generator.run(m_nodes, m_spellings);
	checkNodes();
}
示例#7
0
文件: trie.cpp 项目: gottcode/tanglet
Trie::Trie(const QString& word)
{
	TrieGenerator generator(word);
	generator.run(m_nodes, m_spellings);
	checkNodes();
}
示例#8
0
MainWindow::MainWindow(QWidget* parent)
    : QMainWindow(parent), m_view(0)
{
    m_hostInfoManager = new HostInfoManager;

    m_monitor = new Monitor(m_hostInfoManager, this);

    m_viewMode = new QActionGroup(this);

    QMenu* fileMenu = menuBar()->addMenu(tr("&File"));
    QAction* quitAction = fileMenu->addAction(tr("&Quit"));
    quitAction->setShortcut(QKeySequence::Quit);
    connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));

    QMenu* viewMenu = menuBar()->addMenu(tr("&View"));
    QMenu* modeMenu = viewMenu->addMenu(tr("&Mode"));

    m_listView = modeMenu->addAction(tr("&List View"));
    m_listView->setCheckable(true);
    m_viewMode->addAction(m_listView);
    connect(m_listView, SIGNAL(triggered()), this, SLOT(setupListView()));

    m_starView = modeMenu->addAction(tr("&Star View"));
    m_starView->setCheckable(true);
    m_viewMode->addAction(m_starView);
    connect(m_starView, SIGNAL(triggered()), this, SLOT(setupStarView()));

    m_detailedView = modeMenu->addAction(tr("&Detailed Host View"));
    m_detailedView->setCheckable(true);
    m_viewMode->addAction(m_detailedView);
    connect(m_detailedView, SIGNAL(triggered()), this, SLOT(setupDetailedHostView()));


    QAction* actionStart = viewMenu->addAction(tr("&Start"));
    connect(actionStart, SIGNAL(triggered()), this, SLOT(startView()));
    QAction* actionStop = viewMenu->addAction(tr("Stop"));
    connect(actionStop, SIGNAL(triggered()), this, SLOT(stopView()));
    viewMenu->addSeparator();
    QAction* actionCheckNodes = viewMenu->addAction(tr("Check Nodes"));
    connect(actionCheckNodes, SIGNAL(triggered()), this, SLOT(checkNodes()));
    viewMenu->addSeparator();
    m_configView = viewMenu->addAction(tr("Configure View..."));
    connect(m_configView, SIGNAL(triggered()), this, SLOT( configureView()));

    m_systrayAction = viewMenu->addAction(tr("System Tray"));
    m_systrayAction->setCheckable(true);

    QMenu* helpMenu = menuBar()->addMenu(tr("&Help"));
    helpMenu->addAction(tr("About..."), this, SLOT(showAboutDialog()));

    readSettings();

    // Avoid useless creation and connection if the system does not have a systray
    if (QSystemTrayIcon::isSystemTrayAvailable()) {
        m_systemTrayIcon = new QSystemTrayIcon(this);
        m_systemTrayIcon->setIcon(QIcon(":bigIcon.png"));

        m_systemTrayMenu = new QMenu(this);
        m_systemTrayMenu->addAction(quitAction);

        m_systemTrayIcon->setContextMenu(m_systemTrayMenu);

        connect(m_systemTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
                this, SLOT(systemTrayIconActivated(QSystemTrayIcon::ActivationReason)));

        connect(m_systrayAction, SIGNAL(triggered(bool)), m_systemTrayIcon, SLOT(setVisible(bool)));

        // Only show the systray if enabled
        if (m_systrayAction->isChecked())
            m_systemTrayIcon->show();
    } else {
        m_systrayAction->setEnabled(false);
    }

    setWindowIcon(QIcon(":bigIcon.png"));

    m_monitor->checkScheduler();
}
void
NIImporter_VISUM::parse_Edges() {
    if (myLineParser.know("VSYSSET") && myLineParser.get("VSYSSET") == "") {
        // no vehicle allowed; don't add
        return;
    }
    // get the id
    myCurrentID = NBHelpers::normalIDRepresentation(myLineParser.get("Nr"));
    // get the from- & to-node and validate them
    NBNode* from = getNamedNode("VonKnot", "VonKnotNr");
    NBNode* to = getNamedNode("NachKnot", "NachKnotNr");
    if (!checkNodes(from, to)) {
        return;
    }
    // get the type
    std::string type = myLineParser.know("Typ") ? myLineParser.get("Typ") : myLineParser.get("TypNr");
    // get the speed
    SUMOReal speed = myNetBuilder.getTypeCont().getSpeed(type);
    if (!OptionsCont::getOptions().getBool("visum.use-type-speed")) {
        try {
            std::string speedS = myLineParser.know("v0-IV") ? myLineParser.get("v0-IV") : myLineParser.get("V0IV");
            if (speedS.find("km/h") != std::string::npos) {
                speedS = speedS.substr(0, speedS.find("km/h"));
            }
            speed = TplConvert::_2SUMORealSec(speedS.c_str(), -1);
            speed = speed / (SUMOReal) 3.6;
        } catch (OutOfBoundsException) {}
    }
    if (speed <= 0) {
        speed = myNetBuilder.getTypeCont().getSpeed(type);
    }

    // get the information whether the edge is a one-way
    bool oneway = myLineParser.know("Einbahn")
                  ? TplConvert::_2bool(myLineParser.get("Einbahn").c_str())
                  : true;
    // get the number of lanes
    int nolanes = myNetBuilder.getTypeCont().getNumLanes(type);
    if (!OptionsCont::getOptions().getBool("visum.recompute-lane-number")) {
        try {
            if (!OptionsCont::getOptions().getBool("visum.use-type-laneno")) {
                nolanes = myLineParser.know("Fahrstreifen")
                          ? TplConvert::_2intSec(myLineParser.get("Fahrstreifen").c_str(), 0)
                          : TplConvert::_2intSec(myLineParser.get("ANZFAHRSTREIFEN").c_str(), 0);
            }
        } catch (UnknownElement) {
        }
    } else {
        SUMOReal cap = myLineParser.know("KAPIV")
                       ? TplConvert::_2SUMORealSec(myLineParser.get("KAPIV").c_str(), -1)
                       : TplConvert::_2SUMORealSec(myLineParser.get("KAP-IV").c_str(), -1);
        nolanes = myCapacity2Lanes.get(cap);
    }
    // check whether the id is already used
    //  (should be the opposite direction)
    bool oneway_checked = oneway;
    NBEdge* previous = myNetBuilder.getEdgeCont().retrieve(myCurrentID);
    if (previous != 0) {
        myCurrentID = '-' + myCurrentID;
        previous->setLaneSpreadFunction(LANESPREAD_RIGHT);
        oneway_checked = false;
    }
    if (find(myTouchedEdges.begin(), myTouchedEdges.end(), myCurrentID) != myTouchedEdges.end()) {
        oneway_checked = false;
    }
    std::string tmpid = '-' + myCurrentID;
    if (find(myTouchedEdges.begin(), myTouchedEdges.end(), tmpid) != myTouchedEdges.end()) {
        previous = myNetBuilder.getEdgeCont().retrieve(tmpid);
        if (previous != 0) {
            previous->setLaneSpreadFunction(LANESPREAD_RIGHT);
        }
        oneway_checked = false;
    }
    // add the edge
    int prio = myUseVisumPrio ? myNetBuilder.getTypeCont().getPriority(type) : -1;
    if (nolanes != 0 && speed != 0) {
        LaneSpreadFunction lsf = oneway_checked ? LANESPREAD_CENTER : LANESPREAD_RIGHT;
        // @todo parse name from visum files
        NBEdge* e = new NBEdge(myCurrentID, from, to, type, speed, nolanes, prio,
                               NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET, "", lsf);
        if (!myNetBuilder.getEdgeCont().insert(e)) {
            delete e;
            WRITE_ERROR("Duplicate edge occured ('" + myCurrentID + "').");
        }
    }
    myTouchedEdges.push_back(myCurrentID);
    // nothing more to do, when the edge is a one-way street
    if (oneway) {
        return;
    }
    // add the opposite edge
    myCurrentID = '-' + myCurrentID;
    if (nolanes != 0 && speed != 0) {
        LaneSpreadFunction lsf = oneway_checked ? LANESPREAD_CENTER : LANESPREAD_RIGHT;
        // @todo parse name from visum files
        NBEdge* e = new NBEdge(myCurrentID, from, to, type, speed, nolanes, prio,
                               NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET, "", lsf);
        if (!myNetBuilder.getEdgeCont().insert(e)) {
            delete e;
            WRITE_ERROR("Duplicate edge occured ('" + myCurrentID + "').");
        }
    }
    myTouchedEdges.push_back(myCurrentID);
}
 double apply(const AzReadOnlyVector *v_data,
              AzIntArr *ia_node=NULL) const {
     checkNodes("apply");
     return apply(v_data, this, ia_node);
 }
示例#11
0
int main( int argc, char** argv )
{
	bpo::options_description            cmdlineOptions;
	bpo::positional_options_description pod;
	bpo::variables_map                  vm;

	std::string specPath;

	common::level = common::eLogInfo;

	
	// Supported options
	cmdlineOptions.add_options()
		( "help,h",        "produce help message"                    )
		( "spec,s",        bpo::value< std::string >(), "specification file" )
		( "verbose,v",     bpo::value<int>()->default_value( 1 ),      "verbose level (trace, debug, warning, error, fatal)" )
	;

	// Default option
	pod.add( "input", -1 );
	// Parsing options
	try
	{
		bpo::store( bpo::command_line_parser( argc, argv ).options( cmdlineOptions ).positional( pod ).run(), vm);

		// get environment options and parse them
		if( const char* env_options = std::getenv("QC_OPTIONS") )
		{
			const std::vector< std::string > vecOptions = bpo::split_unix( env_options, " " );
			bpo::store(bpo::command_line_parser( vecOptions ).options( cmdlineOptions ).positional( pod ).run(), vm);
		}
		bpo::notify( vm );
	}
	catch( const bpo::error& e)
	{
		LOG_ERROR( "command line error: " << e.what() );
		exit( -2 );
	}
	catch(...)
	{
		LOG_ERROR( "unknown error in command line." );
		exit( -2 );
	}

	switch( vm[ "verbose" ].as< int >() )
	{
		case 0 :  common::level = common::eLogTrace;   break;
		case 1 :  common::level = common::eLogInfo;    break;
		case 2 :  common::level = common::eLogWarning; break;
		case 3 :  common::level = common::eLogError;   break;
		case 4 :  common::level = common::eLogFatal;   break;
		default : common::level = common::eLogWarning;    break;
	}


	if( vm.count( "spec" ) )
	{
		specPath = vm[ "spec" ].as< std::string >();
	}

	if( vm.count( "help" ) || specPath.empty() )
	{
		common::level = common::eLogInfo;
		LOG_INFO( common::details::kColorBlue  << "Spec Checker project"                  << common::details::kColorStd << std::endl );
		LOG_INFO( common::details::kColorBlue  << "NAME"                                   << common::details::kColorStd );
		LOG_INFO( common::details::kColorGreen << "\tSpecChecker"                      << common::details::kColorStd << std::endl );
		LOG_INFO( common::details::kColorBlue  << "SYNOPSIS"                               << common::details::kColorStd );
		LOG_INFO( common::details::kColorGreen << "\tspecChecker [options] -s [file]" << common::details::kColorStd << std::endl );
		LOG_INFO( common::details::kColorBlue  << "DESCRIPTION"                            << common::details::kColorStd << std::endl );

		LOG_INFO( "Spec Validation schema." << std::endl );
		LOG_INFO( common::details::kColorBlue  << "OPTIONS" << common::details::kColorStd << std::endl );
		LOG_INFO( cmdlineOptions );
		return 0;
	}

	try
	{
		spec_reader::SpecChecker specChecker( specPath );

		if( ! specChecker.check() )
			throw std::runtime_error( "Cannot open specification file: " + specPath );

		spec_reader::Specification spec;
		spec.setFromString( specChecker.getSpecString() );

		LOG_INFO( common::details::kColorCyan << "Specification: " << spec.getId() << " (" << spec.getType() << ")" << common::details::kColorStd << std::endl );
		checkNodes( spec.getFirstNode() );
	}
	catch( std::runtime_error e )
	{
		LOG_FATAL( "Runtime error: " << e.what() );
		exit( -2 );
	}
	catch( std::exception e )
	{
		LOG_FATAL( "Error: " << e.what() );
		exit( -2 );
	}

	return 0;
}