Example #1
0
/*******************************************************************
* Function Name: initFunction
********************************************************************/
Model &Transducer2::initFunction()
{
	procCount ( 0 ) ;
	cpuLoad ( 0 );
	unsolved().erase( unsolved().begin(), unsolved().end() ) ;
	holdIn( AtomicState::active, frecuence() ) ;
	return *this ;
}
Example #2
0
int main(void){
	int i,j,k;
	int hint;

	for(i=0;i<BL_SIZE;i++)
		for(j=0;j<BL_SIZE;j++){
			boff[BL_SIZE*i+j] = j + SU_SIZE*i;
			bidx[BL_SIZE*i+j] = BL_SIZE*(j + SU_SIZE*i);
		}

	/*initialize field - everything is possible*/
	for(i=0;i<SU_SIZE;i++)
		for(j=0;j<SU_SIZE;j++)
			for(k=0;k<SU_SIZE;k++)
				field[i][j][k] = 1;

	/*initialize sol*/
	for(i=0;i<SU_SIZE;i++)
		for(j=0;j<SU_SIZE;j++)
			sol[i][j] = 0;

	/*read in hints row wise, one at once*/
	for(i=0;i<SU_SIZE;i++){
		for(j=0;j<SU_SIZE;j++){
			scanf("%d\n",&hint);
			printf("%d ",hint);
			set(j,i,hint);
		}
		printf("\n");
	}

	/*solve*/
	while(unsolved()){
		/*check for obvious symbols*/
		int pos;
		for(i=0;i<SU_SIZE;i++)
			for(j=0;j<SU_SIZE;j++){
				pos = -1;
				for(k=0;k<SU_SIZE;k++){
					if(field[i][j][k] == 1 && pos == -1){
						pos = k;
					} else if(pos != -1){
						pos = -2;
					}
				}
				if(pos >= 0)
					set(j,i,pos);
				}
	}

	/*print out solution*/
	for(i=0;i<SU_SIZE;i++){
		for(j=0;j<SU_SIZE;j++)
			printf("%d ",sol[i][j]);
		printf("\n");
	}
}
Example #3
0
/*******************************************************************
* Function Name: externalFunction
********************************************************************/
Model &Transducer2::externalFunction( const ExternalMessage &msg )
{
	long id;
	union request req;
	cpuLoad ( cpuLoad() + static_cast< long >( ( msg.time() - lastChange() ).asMsecs() * unsolved().size() ));

	if( msg.port() == arrived )
	{
		req = (union request) msg.value();
		id = req.r.idtask * 100 + req.r.origin;		

		if( unsolved().find( id ) != unsolved().end() )
		{
			MException e( string("Unresolved Work Id: ") + (float) id + " is duplicated." );
			e.addLocation( MEXCEPTION_LOCATION() );
			throw e;
		}

		unsolved()[ id ] = msg.time() ;
	}

	if( msg.port() == solved )
	{
		req = (union request) msg.value();
		id = req.r.idtask * 100 + req.r.destino;	

		Transducer2State::JobsList::iterator cursor( unsolved().find( id) ) ;

		if( cursor == unsolved().end() )
		{
			MException e( string("Resolved Work Id: ") + (float) id + " Not Found!" );
			e.addLocation( MEXCEPTION_LOCATION() );
			throw e;
		}

		procCount( procCount() + 1 );
		unsolved().erase( cursor ) ;
	}
	return *this ;
}
Example #4
0
/*******************************************************************
* Function Name: outputFunction
********************************************************************/
Model &Transducer2::outputFunction( const CollectMessage &msg )
{
	float time( msg.time().asMsecs() / timeUnit().asMsecs() ) ;

	sendOutput( msg.time(), throughput, procCount() / time ) ;

	cpuLoad ( cpuLoad() + static_cast< long >( ( msg.time() - lastChange() ).asMsecs() * unsolved().size() )) ;

	sendOutput( msg.time(), cpuUsage  , cpuLoad() / msg.time().asMsecs() ) ;

	sendOutput( msg.time(), responsetime, (cpuLoad() / msg.time().asMsecs() ) / (procCount() / time) ); 

	return *this ;
}