Exemplo n.º 1
0
   /**
   * Set properties of this connection from position p in the properties
   * array given in dictionary.
   */
  void ContDelayConnection::set_status(const DictionaryDatum & d, index p, ConnectorModel &cm)
  {

     //set delay if mentioned
    double_t delay;
    if ( set_property<double_t>(d, names::delays, p, delay) )
      {

	double_t h = Time::get_resolution().get_ms();

	double_t int_delay;
	double_t frac_delay = std::modf(delay/h, &int_delay);

	if (frac_delay == 0)
	  {
	    if (!cm.check_delay(delay))
	      throw BadDelay(delay);
	    delay_ = Time(Time::ms(delay)).get_steps();
	    delay_offset_ = 0.0;
	  }
	else
	  {
	    long_t lowerbound = static_cast<long_t>(int_delay);
	    if (!cm.check_delays(Time(Time::step(lowerbound)).get_ms(),
				 Time(Time::step(lowerbound + 1)).get_ms()))
	      throw BadDelay(lowerbound);
	    delay_ = lowerbound + 1; 
	    delay_offset_ = h * (1.0 - frac_delay);
	  }
      }
    set_property<double_t>(d, names::weights, p, weight_); 
  }
void
nest::DelayChecker::assert_two_valid_delays_steps( delay new_delay1,
  delay new_delay2 )
{
  const delay ldelay = std::min( new_delay1, new_delay2 );
  const delay hdelay = std::max( new_delay1, new_delay2 );

  if ( ldelay < Time::get_resolution().get_steps() )
    throw BadDelay( Time::delay_steps_to_ms( ldelay ),
      "Delay must be greater than or equal to resolution" );

  if ( kernel().simulation_manager.has_been_simulated() )
  {
    const bool bad_min_delay =
      ldelay < kernel().connection_manager.get_min_delay();
    const bool bad_max_delay =
      hdelay > kernel().connection_manager.get_max_delay();

    if ( bad_min_delay )
      throw BadDelay( Time::delay_steps_to_ms( ldelay ),
        "Minimum delay cannot be changed after Simulate has been called." );

    if ( bad_max_delay )
      throw BadDelay( Time::delay_steps_to_ms( hdelay ),
        "Maximum delay cannot be changed after Simulate has been called." );
  }

  const bool new_min_delay = ldelay < min_delay_.get_steps();
  const bool new_max_delay = hdelay > max_delay_.get_steps();

  if ( new_min_delay )
  {
    if ( user_set_delay_extrema_ )
    {
      throw BadDelay( Time::delay_steps_to_ms( ldelay ),
        "Delay must be greater than or equal to min_delay. "
        "You may set min_delay before creating connections." );
    }
    else
    {
      if ( not freeze_delay_update_ )
        min_delay_ = Time( Time::step( ldelay ) );
    }
  }

  if ( new_max_delay )
  {
    if ( user_set_delay_extrema_ )
    {
      throw BadDelay( Time::delay_steps_to_ms( hdelay ),
        "Delay must be smaller than or equal to max_delay. "
        "You may set max_delay before creating connections." );
    }
    else
    {
      if ( not freeze_delay_update_ )
        max_delay_ = Time( Time::step( hdelay ) );
    }
  }
}
void
nest::DelayChecker::assert_valid_delay_ms( double_t requested_new_delay )
{
  const delay new_delay = Time::delay_ms_to_steps( requested_new_delay );
  const double new_delay_ms = Time::delay_steps_to_ms( new_delay );

  if ( new_delay < Time::get_resolution().get_steps() )
    throw BadDelay(
      new_delay_ms, "Delay must be greater than or equal to resolution" );

  // if already simulated, the new delay has to be checked against the
  // min_delay and the max_delay which have been used during simulation
  if ( kernel().simulation_manager.has_been_simulated() )
  {
    const bool bad_min_delay =
      new_delay < kernel().connection_manager.get_min_delay();
    const bool bad_max_delay =
      new_delay > kernel().connection_manager.get_max_delay();

    if ( bad_min_delay || bad_max_delay )
      throw BadDelay( new_delay_ms,
        "Minimum and maximum delay cannot be changed "
        "after Simulate has been called." );
  }

  const bool new_min_delay = new_delay < min_delay_.get_steps();
  const bool new_max_delay = new_delay > max_delay_.get_steps();

  if ( new_min_delay )
  {
    if ( user_set_delay_extrema_ )
    {
      throw BadDelay( new_delay_ms,
        "Delay must be greater than or equal to min_delay. "
        "You may set min_delay before creating connections." );
    }
    else
    {
      if ( not freeze_delay_update_ )
        min_delay_ = Time( Time::step( new_delay ) );
    }
  }

  if ( new_max_delay )
  {
    if ( user_set_delay_extrema_ )
    {
      throw BadDelay( new_delay_ms,
        "Delay must be smaller than or equal to max_delay. "
        "You may set min_delay before creating connections." );
    }
    else
    {
      if ( not freeze_delay_update_ )
        max_delay_ = Time( Time::step( new_delay ) );
    }
  }
}
void
nest::DelayChecker::set_status( const DictionaryDatum& d )
{
  // For the minimum delay, we always round down. The easiest way to do this,
  // is to round up and then subtract one step. The only remaining edge case
  // is that the min delay is exactly at a step, in which case one would get
  // a min delay that is one step too small. We can detect this by an
  // additional test.
  double_t delay_tmp = 0.0;
  bool min_delay_updated = updateValue< double_t >( d, "min_delay", delay_tmp );
  Time new_min_delay;
  if ( min_delay_updated )
  {
    delay new_min_delay_steps = Time( Time::ms_stamp( delay_tmp ) ).get_steps();
    if ( Time( Time::step( new_min_delay_steps ) ).get_ms() > delay_tmp )
    {
      new_min_delay_steps -= 1;
    }
    new_min_delay = Time( Time::step( new_min_delay_steps ) );
  }

  // For the maximum delay, we always round up, using ms_stamp
  bool max_delay_updated = updateValue< double_t >( d, "max_delay", delay_tmp );
  Time new_max_delay = Time( Time::ms_stamp( delay_tmp ) );

  if ( min_delay_updated xor max_delay_updated )
  {
    throw BadProperty( "Both min_delay and max_delay have to be specified" );
  }

  if ( min_delay_updated && max_delay_updated )
  {
    if ( kernel().connection_manager.get_num_connections() > 0 )
    {
      throw BadProperty(
        "Connections already exist. Please call ResetKernel first" );
    }
    else if ( new_min_delay < Time::get_resolution() )
    {
      throw BadDelay( new_min_delay.get_ms(),
        "min_delay must be greater than or equal to resolution." );
    }
    else if ( new_max_delay < new_min_delay )
    {
      throw BadDelay( new_min_delay.get_ms(),
        "min_delay must be smaller than or equal to max_delay." );
    }
    else
    {
      min_delay_ = new_min_delay;
      max_delay_ = new_max_delay;
      user_set_delay_extrema_ = true;
    }
  }
}
Exemplo n.º 5
0
  void CommonPropertiesHomWD::set_status(const DictionaryDatum & d, ConnectorModel &cm)
  {
    CommonSynapseProperties::set_status(d, cm);

    double_t delay;

    if (updateValue<double_t>(d, names::delay, delay))
      {
	if (!cm.check_delay(delay))
	  throw BadDelay(delay);
	delay_ = Time(Time::ms(delay)).get_steps();
      }

    updateValue<double_t>(d, names::weight, weight_);
  }