⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsched.cpp

📁 a useful spiking neural networks simulator
💻 CPP
字号:
/**  * @file  dsched.cpp * @brief Event, Action, Scheduler * * @author Makino, Takaki <t-makino-punnets01@snowelm.com> * @date 2003-05-01 * @version $Id: dsched.cpp,v 1.1 2003/05/01 10:57:43 t Exp $ * *  Copyright (C) 2003 Makino, Takaki.  * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2, or (at your option) *  any later version. *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   */#include "dsched.h"/////////////////////////////////////////////////////////////////////////namespace punnets_common {//////////////////////////////////////////////////////////////////////////** Sentinel action. * *  This class is used to mark the end of the simulation range. */class tsentinel : public taction{	bool processed;public:	tsentinel() : taction(), processed(false) { }	bool isProcessed() { return processed; }		virtual void activate(tscheduler &, ntime_t) 		{ 			processed = true;		}	tqueue *queue() const{ return NULL; }	virtual const char *getClassName() const { return "tsentinel"; };};tsched_double::tsched_double() {}void tsched_double::scheduleEvent(const tevent &event){	tqueue *q = event.getAction().queue();	bool need_insert = false;	if( q != processing_queue )	{		if( q->empty() )			need_insert = true;		else {			ntime_t prev_top = q->top().getTime();			if( prev_top > event.getTime() )			{				global_queue.erase(make_pair(prev_top, q));				need_insert = true;			}		}	}	q->push(event);	if( need_insert )		global_queue.insert(make_pair(event.getTime(), q));}ntime_t tsched_double::run(ntime_t until /* = HUGE_VAL */ ){	ntime_t ret = 0.0, retp = 0.0;	tsentinel sentinel;		global_queue.insert( sched_entry( until, NULL ) );//	unsigned int c = 0;	std::set< sched_entry, less_sched_entry >::iterator i = global_queue.begin();	while( i->second != NULL )	{		tqueue *q = i->second;		processing_queue = q;		tevent event = q->top();		q->pop();		global_queue.erase(i);		event.activate( *this );		if( ! q->empty() )			global_queue.insert( make_pair( q->top().getTime(), q ) );//		if( ((++c) & 65535) == 0 )//			cout << ret << "      \r";		i = global_queue.begin();	}	global_queue.erase(i);	return retp;}/////////////////////////////////////////////////////////////////////////} // namespace punnets_common/////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -