Ejemplo n.º 1
0
void Check::performCallback(NodeID proc, SubBlock& data)
{
    Address address = data.getAddress();
    //  assert(getAddress() == address);  // This isn't exactly right since we now have multi-byte checks
    assert(getAddress().getLineAddress() == address.getLineAddress());

    DEBUG_MSG(TESTER_COMP, MedPrio, "Callback");
    DEBUG_EXPR(TESTER_COMP, MedPrio, *this);

    if (m_status == TesterStatus_Action_Pending) {
        DEBUG_MSG(TESTER_COMP, MedPrio, "Action callback");
        // Perform store
        data.setByte(0, m_value+m_store_count); // We store one byte at a time
        m_store_count++;

        if (m_store_count == CHECK_SIZE) {
            m_status = TesterStatus_Ready;
        } else {
            m_status = TesterStatus_Idle;
        }
    } else if (m_status == TesterStatus_Check_Pending) {
        DEBUG_MSG(TESTER_COMP, MedPrio, "Check callback");
        // Perform load/check
        for(int byte_number=0; byte_number<CHECK_SIZE; byte_number++) {
            if (uint8(m_value+byte_number) != data.getByte(byte_number) && (DATA_BLOCK == true)) {
                WARN_EXPR(proc);
                WARN_EXPR(address);
                WARN_EXPR(data);
                WARN_EXPR(byte_number);
                WARN_EXPR((int)m_value+byte_number);
                WARN_EXPR((int)data.getByte(byte_number));
                WARN_EXPR(*this);
                WARN_EXPR(g_eventQueue_ptr->getTime());
                ERROR_MSG("Action/check failure");
            }
        }
        DEBUG_MSG(TESTER_COMP, HighPrio, "Action/check success:");
        DEBUG_EXPR(TESTER_COMP, HighPrio, *this);
        DEBUG_EXPR(TESTER_COMP, MedPrio, data);

        m_status = TesterStatus_Idle;
        pickValue();

    } else {
        WARN_EXPR(*this);
        WARN_EXPR(proc);
        WARN_EXPR(data);
        WARN_EXPR(m_status);
        WARN_EXPR(g_eventQueue_ptr->getTime());
        ERROR_MSG("Unexpected TesterStatus");
    }

    DEBUG_EXPR(TESTER_COMP, MedPrio, proc);
    DEBUG_EXPR(TESTER_COMP, MedPrio, data);
    DEBUG_EXPR(TESTER_COMP, MedPrio, getAddress().getLineAddress());
    DEBUG_MSG(TESTER_COMP, MedPrio, "Callback done");
    DEBUG_EXPR(TESTER_COMP, MedPrio, *this);
}
Ejemplo n.º 2
0
Check::Check(const Address& address, const Address& pc)
{
    m_status = TesterStatus_Idle;

    pickValue();
    pickInitiatingNode();
    changeAddress(address);
    m_pc = pc;
    m_access_mode = AccessModeType(random() % AccessModeType_NUM);
    m_store_count = 0;
}
Ejemplo n.º 3
0
//---------------------------------------------------------------------------
bool AntSolver2::solve( int numSteps )
{
	init();	

	vector<int> uninstantiatedVariables( problem->getNumVars(), 0 );	
	vector<int> numSatisfiedConstraints( numAnts );	
	vector< vector<double> > valuesScore( problem->getNumVars() );

	calculateValuesScore( valuesScore );

	MinConflicts *minConflicts = NULL;
	if ( useLocalSearch )
	{
		minConflicts = MinConflicts::create( problem );
	}

	int maxSatisfiedConstraints;

	int i, j;

	for ( i = 0; i < numSteps; i++ )
	{

		maxSatisfiedConstraints = 0;
		vector< CSPInterpretation > interpretations( numAnts );
		for ( j = 0; j < numAnts; j++ )
		{			
			int numVars = problem->getNumVars();

			// Initialize the vector of uninstantiated variables
			int k;
			for ( k = 0; k < numVars; k++ )
			{
				uninstantiatedVariables[k] = k;
			}

			// Build a path			
			
			interpretations[j].setNumVariables( problem->getNumVars() );
			for ( k = 0; k < problem->getNumVars(); k++ )
			{
				// Pick a variable.
				int variable = pickUninstantiatedVariable( interpretations[j], uninstantiatedVariables , problem->getNumVars() - k );
				// pick a value from this variable
				int value    = pickValue( variable, valuesScore );

				interpretations[j].setVariableValue( variable, value );
			}

			if ( useLocalSearch )
			{
				minConflicts->localSearch( interpretations[j], interpretations[j] );
			}

			numSatisfiedConstraints[j] = problem->getNumSatisfiedConstraints( interpretations[j] );
			if ( numSatisfiedConstraints[j] == problem->getConstraintList()->getNumConstraints() )
			{
				result = interpretations[j];
				stepsPerformed = i;
				if ( minConflicts )
					minConflicts->release();
				return true;
			}
			if ( numSatisfiedConstraints[j] > maxSatisfiedConstraints )
			{
				maxSatisfiedConstraints = numSatisfiedConstraints[j];
			}
		}

		// Now that we've built all assignments
		// let's choose the best ones
		// Only the assignmenst with the max number of satisfied
		// constraints will lay pheromone
		for ( j = 0; j < numAnts; j++ )
		{
			if ( numSatisfiedConstraints[j] == maxSatisfiedConstraints )
			{
				layPheromone( interpretations[j] );
			}
		}

		//cout << "Step " << i << ", maxSatisfiedConstraints: " << maxSatisfiedConstraints << endl;
		cout << i << ", " << maxSatisfiedConstraints << endl;
		//if ( i % 10 == 0 )
		{
			//printPheromones ( i, maxSatisfiedConstraints );
		}
	}

	stepsPerformed = i;

	if ( useLocalSearch )
	{
		minConflicts->release();
	}

	return false;
}