コード例 #1
0
void Insert(State *state, Mode mode) {
	State *aux;
	
	if (IsEmpty()) {
		state->value = CalculateValue(state);
		myQueue->firstState = state;
		myQueue->queueHead = state;
		myQueue->numberOfElements++;
	}
	else {
		aux = myQueue->queueHead;

		switch (mode)
		{
			// Breadth First Search
		case 1:
			while (aux->next != NULL) {
				aux = aux->next;
			}
			aux->next = state;
			myQueue->numberOfElements++;
			break;

			// Depth First Search
		case 2:
			state->next = aux->next;
			aux->next = state;
			myQueue->numberOfElements++;
			break;

			// Greedy best-first search
		case 3:
			state->value = CalculateValue(state);
			while ((aux->next != NULL) && (aux->next->value <= state->value)) {
				aux = aux->next;
			}
			state->next = aux->next;
			aux->next = state;
			myQueue->numberOfElements++;
			break;
		case 4:
			break;
		default:
			break;
		}
	}
}
コード例 #2
0
bool CFX_LedAnimationSequence::UpdateAnimation(int timeStep)
{
  bool returnval = false;
  m_stepIncrement++;
  m_output->SetBrightness(CalculateValue(m_stepIncrement, m_totalIncrements, m_startBrightness,
    m_steps[m_activeStep].brightness, m_steps[m_activeStep].type));

  if (m_stepIncrement >= m_totalIncrements)
  {
    returnval = NextStep();
  }
  return returnval;
}
コード例 #3
0
ECode MultiFloatValuesHolder::SetupSetter(
    /* [in] */ IInterface* targetClass)
{
    if (mJniSetter != NULL) {
        return NOERROR;
    }
    // try {
    AutoLock lock(mPropertyMapLock);
    // mPropertyMapLock.writeLock().lock();
    AutoPtr<IClassInfo> info = TransformClassInfo(targetClass);
    AutoPtr<MethodMap> propertyMap = sJNISetterPropertyMap[info];

    typename ClassMethodMap::Iterator it = sJNISetterPropertyMap.Find(info);
    if ((it != sJNISetterPropertyMap.End()) && (it->mSecond != NULL)) {
        propertyMap = it->mSecond;
        typename MethodMap::Iterator it2 = propertyMap->Find(mPropertyName);
        if ((it2 != propertyMap->End()) && (it2->mSecond != NULL)) {
            mJniSetter = it2->mSecond;
        }
    }

    if (mJniSetter == NULL) {
        String methodName = GetMethodName(String("Set"), mPropertyName);
        CalculateValue(0.f);
        AutoPtr<IArrayList> values;
        GetAnimatedValue((IInterface**)&values);
        Int32 numParams = 0;
        values->GetSize(&numParams);

        try {
            mJniSetter = nGetMultipleFloatMethod(info, methodName, numParams);
        } catch (NoSuchMethodError e) {
            // try without the 'set' prefix
            mJniSetter = nGetMultipleFloatMethod(info, mPropertyName, numParams);
        }
        if (mJniSetter != NULL) {
            if (propertyMap == NULL) {
                propertyMap = new MethodMap();
                sJNISetterPropertyMap[info] = propertyMap;
            }
            (*propertyMap)[mPropertyName] = mJniSetter;
        }
    }
    // } finally {
    //     mPropertyMapLock.writeLock().unlock();
    // }
    return NOERROR;
}
コード例 #4
0
//The CAN receive interruption function 
interrupt void CANARX_ISR(void)
{
	struct ECAN_REGS ECanaShadow;
	Uint16 CANRX_MSGID;

	ECanaShadow.CANRMP.all = ECanaRegs.CANRMP.all;
	ECanaShadow.CANRMP.bit.RMP0 = 1;//clear  RMLIF0(接收邮箱溢出) by set RMP0
	ECanaRegs.CANRMP.all = ECanaShadow.CANRMP.all;

	CANRX_MSGID = ECanaMboxes.MBOX0.MSGID.bit.STDMSGID;

	if (CANRX_MSGID == 0x100)
	{
		struct CANFrame frame;
		frame.data[0] = ECanaMboxes.MBOX0.MDL.byte.BYTE0;
		frame.data[1] = ECanaMboxes.MBOX0.MDL.byte.BYTE1;
		frame.data[2] = ECanaMboxes.MBOX0.MDL.byte.BYTE2;
		frame.data[3] = ECanaMboxes.MBOX0.MDL.byte.BYTE3;
		frame.data[4] = ECanaMboxes.MBOX0.MDH.byte.BYTE4;
		frame.data[5] = ECanaMboxes.MBOX0.MDH.byte.BYTE5;
		frame.data[6] = ECanaMboxes.MBOX0.MDH.byte.BYTE6;
		frame.data[7] = ECanaMboxes.MBOX0.MDH.byte.BYTE7;
		CalculateValue(&frame);
		//处理信息
		HandleMessage(&frame);
	}
	PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;

	if (SendQGetLength())
	{
		struct CANFrame frame;

		SendQPopFront(&frame);

		ECanaMboxes.MBOX1.MDL.byte.BYTE0 = frame.data[0];
		ECanaMboxes.MBOX1.MDL.byte.BYTE1 = frame.data[1];
		ECanaMboxes.MBOX1.MDL.byte.BYTE2 = frame.data[2];
		ECanaMboxes.MBOX1.MDL.byte.BYTE3 = frame.data[3];
		ECanaMboxes.MBOX1.MDH.byte.BYTE4 = frame.data[4];
		ECanaMboxes.MBOX1.MDH.byte.BYTE5 = frame.data[5];
		ECanaMboxes.MBOX1.MDH.byte.BYTE6 = frame.data[6];
		ECanaMboxes.MBOX1.MDH.byte.BYTE7 = frame.data[7];

		ECanaShadow.CANTRS.all = 0;
		ECanaShadow.CANTRS.bit.TRS1 = 1;
		ECanaRegs.CANTRS.all = ECanaShadow.CANTRS.all;
	}
}
コード例 #5
0
ファイル: overshoot_processor.cpp プロジェクト: 1yvT0s/motive
  virtual void AdvanceFrame(MotiveTime delta_time) {
    Defragment();

    // Loop through every motivator one at a time.
    // TODO: change this to a closed-form equation.
    // TODO OPT: reorder data and then optimize with SIMD to process in groups
    // of 4 floating-point or 8 fixed-point values.
    for (auto d = data_.begin(); d < data_.end(); ++d) {
      for (MotiveTime time_remaining = delta_time; time_remaining > 0;) {
        MotiveTime dt = std::min(time_remaining, d->init.max_delta_time());

        d->velocity = CalculateVelocity(dt, *d);
        d->value = CalculateValue(dt, *d);

        time_remaining -= dt;
      }
    }
  }
コード例 #6
0
ファイル: Slider.cpp プロジェクト: Landeplage/Amigo
// Handle the movement of buttons
void Slider::HandleButton(Button *button, GLint limitXLeft, GLint limitXRight, GLint maxPos, GLint minPos, GLfloat *value)
{
	// Sync the button
	button->active = active;
	button->visible = visible;

	// Get the mouse-offset as the button is clicked
	if (menuSystem->GetFocus() == button && Input::getMouseLeftPressed())
	{
		mouseOffset = button->GetPosition() - Input::getMousePos() - button->GetOrigin();
	}

	// Get button-input
	if (menuSystem->GetFocus() == button && button->GetState() == 2)
	{
		// Button is pressed
		if (Input::getMouseLeft())
		{
			Vec2 mouse = Input::getMousePos() + origin;

			// Move the button
			button->SetPosition(Vec2(mouse.x + mouseOffset.x, button->GetPosition().y));

			// Clamp the button's movement
			GLint sliderX, buttonX;
			sliderX = (GLint)position.x;
			buttonX = (GLint)button->GetPosition().x;
			if (buttonX < sliderX + minPos) button->SetPosition(Vec2(sliderX + minPos, button->GetPosition().y));
			if (buttonX > sliderX + maxPos) button->SetPosition(Vec2(sliderX + maxPos, button->GetPosition().y));
			if (buttonX < limitXLeft) button->SetPosition(Vec2(limitXLeft, button->GetPosition().y));
			if (buttonX > limitXRight) button->SetPosition(Vec2(limitXRight, button->GetPosition().y));

			// Set the mouse-position to the button's position
			//Input::setMousePos(Vec2(Input::getMousePos().x, button->GetPosition().y - origin.y - mouseOffset.y));

			// Calculate the new value of the slider
			CalculateValue(button, maxPos, minPos, value);

			// Check if step is enabled and move button to correct position
			SnapButton(button, value, limitXLeft, limitXRight, maxPos, minPos);
		}
	}
}
コード例 #7
0
ファイル: mpi_he.cpp プロジェクト: Runli/mipt-assignments
int main (int argc, char** argv) {
  assert(argc == 2);
  int coordinate_steps = atoi(argv[1]);

  double length = 1.0;
  double total_time = 0.6;

  double sigma = 0.3;
  double lambda = 1.0;

  double boundary_value = 0.0;

  double coordinate_step = length / coordinate_steps;
  double time_step = sigma * coordinate_step / lambda;

  int time_steps = total_time / time_step;

  int rv = MPI_Init(&argc, &argv);
  assert(rv == MPI_SUCCESS);

  int size;
  rv = MPI_Comm_size(MPI_COMM_WORLD, &size);
  assert(rv == MPI_SUCCESS);

  int rank;
  rv = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  assert(rv == MPI_SUCCESS);

  MPI_Request request;
  MPI_Status status;

  std::vector<double> current_values(coordinate_steps, 0.0);
  std::vector<double> previous_values(coordinate_steps, 0.0);
  double start_time = MPI_Wtime();

  if (rank == 0) {
    for (int s = 0; s <= coordinate_steps; s++) {
      double coordinate = static_cast<double>(s) / coordinate_steps * length;
      if (coordinate >= 0.1 && coordinate <= 0.2) {
        current_values[s] = 1.0;
      }
    }
  }

  if (rank == 0) {
    for (int s = 0; s <= coordinate_steps; s++) {
      rv = MPI_Isend(&current_values[s], 1, MPI_DOUBLE, Next(rank, size), s, MPI_COMM_WORLD, &request);
      assert(rv == MPI_SUCCESS);
      rv = MPI_Request_free(&request);
      assert(rv == MPI_SUCCESS);
    }
  }

  for (int i = (rank == 0) ? 1 : 0; i * size + rank <= time_steps; i++) {
    for (int s = 0; s <= coordinate_steps; s++) {
      rv = MPI_Recv(&previous_values[s], 1, MPI_DOUBLE, Prev(rank, size), s, MPI_COMM_WORLD, &status);
      assert(rv == MPI_SUCCESS);

      double left_value = (s == 0) ? boundary_value : current_values[s - 1];
      double left_down_value = (s == 0) ? boundary_value : previous_values[s - 1];
      double down_value = previous_values[s];

      current_values[s] = CalculateValue(sigma, left_value, down_value, left_down_value);

      int receiver = (i * size + rank == time_steps) ? 0 : Next(rank, size);
      rv = MPI_Isend(&current_values[s], 1, MPI_DOUBLE, receiver, s, MPI_COMM_WORLD, &request);
      assert(rv == MPI_SUCCESS);
      rv = MPI_Request_free(&request);
      assert(rv == MPI_SUCCESS);
    }
  }

  if (rank == 0) {
    for (int s = 0; s <= coordinate_steps; s++) {
      int sender = time_steps % size;
      rv = MPI_Recv(&previous_values[s], 1, MPI_DOUBLE, sender, s, MPI_COMM_WORLD, &status);
      assert(rv == MPI_SUCCESS);
    }
  }

  if (rank == 0 && coordinate_steps <= 100) {
    for (int s = 0; s <= coordinate_steps; s++) {
      double coordinate = static_cast<double>(s) / coordinate_steps * length;
      printf("%lf %lf\n", coordinate, previous_values[s]);
    }
  }

  if (rank == 0) {
    double current_time = MPI_Wtime();
    printf("%d %lf\n", size, current_time - start_time);
  }

  rv = MPI_Finalize();
  assert(rv == MPI_SUCCESS);

  return EXIT_SUCCESS;
}
double NaturalNeighbourInterpolation (glm::vec3 point, DelaunayTriangulation* dt)
{
	Vertex p;
	p.m_Point[0] =  point.x;
	p.m_Point[1] =  point.y;
	p.m_Point[2] =  point.z;
	p.m_VoronoiVolume = -1;

	ArrayList* neighbours;
	ArrayList* neighbourSimplices;
  
	AddPoint(&p, dt);    

	neighbours = NewArrayList();  
	neighbourSimplices = NewArrayList();  
	LastNaturalNeighbours(&p, dt, neighbours, neighbourSimplices);

	double pointVolume;

	std::vector<double> neighbourVolumes;
	std::vector<double> neighbourWeights;
	neighbourVolumes.resize (ArrayListSize(neighbours));
	neighbourWeights.resize (ArrayListSize(neighbours));

	for (int i = 0; i < ArrayListSize(neighbours); i++)
	{
		Vertex* thisVertex  = static_cast<Vertex*> (GetFromArrayList(neighbours, i));
		Simplex* thisSimplex = static_cast<Simplex*> (GetFromArrayList(neighbourSimplices, i));  
		VoronoiCell* voronoiCell = GetVoronoiCell(thisVertex, thisSimplex, dt);    
		neighbourVolumes[i]  = VoronoiCellVolume(voronoiCell, thisVertex);  
		FreeVoronoiCell(voronoiCell, dt); 
	}

	Simplex* simplex = static_cast<Simplex*> (GetFromArrayList(neighbourSimplices, 0));
	VoronoiCell* pointCell = GetVoronoiCell(&p, simplex, dt);
	pointVolume = VoronoiCellVolume(pointCell, &p);
	FreeVoronoiCell(pointCell, dt);
         
	RemovePoint(dt);

	for (int i = 0; i < ArrayListSize(neighbours); i++)
	{
		Vertex* neighbourVertex   = static_cast<Vertex*> (GetFromArrayList(neighbours, i));  
  
		if (neighbourVertex->m_VoronoiVolume < 0)
		{
			Simplex* s = FindAnyNeighbour(neighbourVertex, dt->m_Conflicts);
			VoronoiCell* voronoiCell      = GetVoronoiCell(neighbourVertex, s, dt);
			neighbourVertex->m_VoronoiVolume = VoronoiCellVolume(voronoiCell, neighbourVertex);
			FreeVoronoiCell(voronoiCell, dt);
		}
		double neighbourVol = neighbourVertex->m_VoronoiVolume-neighbourVolumes[i];
		
		assert (neighbourVolumes[i]>= -0.001);
		neighbourWeights[i] = neighbourVol/pointVolume;
	}

	double result = CalculateValue (neighbours, neighbourWeights);

	for (int i = 0; i <ArrayListSize(dt->m_Updates); i++)
	  Push(dt->m_RemovedSimplices, GetFromArrayList(dt->m_Updates, i));

	EmptyArrayList(dt->m_Conflicts);
	EmptyArrayList(dt->m_Updates);
  
	FreeArrayList(neighbours, nullptr);
	FreeArrayList(neighbourSimplices, nullptr);

	return result;
}