Example #1
0
/**
 * allocate the array for centroids, then pick the initial centroids
 */
void setup_centroids()
{
  uint i, j, k, x, y;
  struct timeval tv;

  // seed rand with microseconds to increase variance if called repeatedly quickly
  gettimeofday(&tv, NULL);
  srand(tv.tv_usec);

  // allocate centroids array
  centroids = (centroid *)calloc(num_clusters, sizeof(centroid));

  // pick starting centroids, ensuring uniqueness
  for (i = 0; i < num_clusters; ) {
    // grab a random data point
    j = random() % num_points;

    // take if first one or unassigned
    if (i == 0 || !is_assigned(j)) {
      centroids[i].point_id = j;

      // mark this point (and all points like it) as assigned;
      // this traversal works because we know the data set is sorted
      x = datax(j);
      y = datay(j);
      for (k = j; k < num_points && x == datax(k) && y == datay(k); k++)
        set_assigned(k);
      for (k = j; k-- > 0 && x == datax(k) && y == datay(k); )
        set_assigned(k);

      // on to next centroid
      i++;
    }

    // done if all assigned
    for (j = 0; j < num_points; j++)
      if (!is_assigned(j)) break;
    if (j >= num_points) break;
  }

  // it's possible that the actual number of clusters is less than asked for
  if (i < num_clusters)
    num_clusters = i;

  #ifdef DEBUG
  for (uint pid = 0, i = 0; i < num_clusters; i++) {
    pid = centroids[i].point_id;
    printf("centroids[%d]: point_id = %d (%d, %d)\n", i, pid, datax(pid), datay(pid));
  }
  #endif
}
Example #2
0
	void exec() throw( general_error )
	{
		double I = as_double("I");
		double T = as_double("T");
		util::matrix_t<double> data = as_matrix("input");
		util::matrix_t<double> par = as_matrix("param");

		if ( data.ncols() != DATACOLS )
			throw general_error( util::format("input matrix must have 6 columns (Irr, Tc, Pmp, Vmp, Voc, Isc), but is %d x %d", 
				(int)data.nrows(), (int)data.ncols() ) );

		if ( par.ncols() != PARCOLS )
			throw general_error( util::format("parameter matrix must have 5 columns (Il, Io, Rs, Rsh, a), but is %d x %d",
				(int)par.nrows(), (int)par.ncols() ) );

		if ( par.nrows() != data.nrows() || data.nrows() < 3 )
			throw general_error( "input and parameter matrices must have same number of rows, and at least 3" );

		bool quiet = false;
		if ( is_assigned( "quiet" ) )
			quiet = true;

		assign( "a", var_data((ssc_number_t) interpolate( data, par, I, T, A, quiet ) ) );
		assign("Il", var_data((ssc_number_t)interpolate(data, par, I, T, IL, quiet)));
		assign("Io", var_data((ssc_number_t)interpolate(data, par, I, T, IO, quiet)));
		assign("Rs", var_data((ssc_number_t)interpolate(data, par, I, T, RS, quiet)));
		assign("Rsh", var_data((ssc_number_t)interpolate(data, par, I, T, RSH, quiet)));

	}
Example #3
0
bool burst_serv::will_process(const std::string& keyword) const {
#ifdef HAVE_ZOOKEEPER_H
  const server_argv& a = argv();
  if (a.is_standalone()) {
#endif
    return true;
#ifdef HAVE_ZOOKEEPER_H
  } else {
    common::cht cht(zk_, a.type, a.name);
    return is_assigned(cht, keyword, a.eth, a.port);
  }
#endif
}
Example #4
0
	void exec( ) throw( general_error )
	{
		size_t arr_len;
		ssc_number_t *p_poabeam = as_array( "poa_beam", &arr_len );
		ssc_number_t *p_poaskydiff = as_array( "poa_skydiff", &arr_len );
		ssc_number_t *p_poagnddiff = as_array( "poa_gnddiff", &arr_len );
		ssc_number_t *p_tdry = as_array( "tdry", &arr_len );
		ssc_number_t *p_wspd = as_array( "wspd", &arr_len );
		ssc_number_t *p_wdir = as_array( "wdir", &arr_len );
		ssc_number_t *p_inc = as_array( "incidence", &arr_len );
		ssc_number_t *p_zen = as_array( "sun_zen", &arr_len );
		ssc_number_t *p_stilt = as_array( "surf_tilt", &arr_len );
		double site_elevation = as_double("elev");

		cec6par_module_t mod;
		mod.Area = as_double("area");
		mod.Vmp = as_double("Vmp");
		mod.Imp = as_double("Imp");
		mod.Voc = as_double("Voc");
		mod.Isc = as_double("Isc");
		mod.alpha_isc = as_double("alpha_isc");
		mod.beta_voc = as_double("beta_voc");
		mod.a = as_double("a");
		mod.Il = as_double("Il");
		mod.Io = as_double("Io");
		mod.Rs = as_double("Rs");
		mod.Rsh = as_double("Rsh");
		mod.Adj = as_double("Adj");

		noct_celltemp_t tc;
		tc.Tnoct = as_double("tnoct");

		int standoff = as_integer("standoff");
		tc.standoff_tnoct_adj = 0;
		switch(standoff)
		{
		case 2: tc.standoff_tnoct_adj = 2; break; // between 2.5 and 3.5 inches
		case 3: tc.standoff_tnoct_adj = 6; break; // between 1.5 and 2.5 inches
		case 4: tc.standoff_tnoct_adj = 11; break; // between 0.5 and 1.5 inches
		case 5: tc.standoff_tnoct_adj = 18; break; // less than 0.5 inches
			// note: all others, standoff_tnoct_adj = 0;
		}

		int height = as_integer("height");
		tc.ffv_wind = 0.51;
		if ( height == 1 )
			tc.ffv_wind = 0.61;

		ssc_number_t *opvoltage = 0;
		if ( is_assigned("opvoltage") )
		{
			size_t opvlen = 0;
			opvoltage = as_array( "opvoltage", &opvlen );
			if ( opvlen != arr_len )
				throw general_error("operating voltage array must be same length as input vectors");
		}

		ssc_number_t *p_tcell = allocate("tcell", arr_len);
		ssc_number_t *p_volt = allocate("dc_voltage", arr_len);
		ssc_number_t *p_amp = allocate("dc_current", arr_len);
		ssc_number_t *p_eff = allocate("eff", arr_len);
		ssc_number_t *p_dc = allocate("dc", arr_len);

		for (size_t i = 0; i < arr_len; i++ )
		{
			pvinput_t in;
			in.Ibeam = (double) p_poabeam[i];
			in.Idiff = (double) p_poaskydiff[i];
			in.Ignd = (double) p_poagnddiff[i];
			in.Tdry = (double) p_tdry[i];
			in.Wspd = (double) p_wspd[i];
			in.Wdir = (double) p_wdir[i];
			in.Zenith = (double) p_zen[i];
			in.IncAng = (double) p_inc[i];
			in.Elev = site_elevation;
			in.Tilt = (double) p_stilt[i];

			pvoutput_t out;

			double opv = -1; // by default, calculate MPPT
			if ( opvoltage != 0 )
				opv = opvoltage[i];

			double tcell = in.Tdry;
			if (! tc( in, mod, opv, tcell ) ) throw general_error("error calculating cell temperature", (float)i);
			if (! mod( in, tcell, opv, out ) ) throw general_error( "error calculating module power and temperature with given parameters", (float) i);

			p_tcell[i] = (ssc_number_t)out.CellTemp;
			p_volt[i] = (ssc_number_t)out.Voltage;
			p_amp[i] = (ssc_number_t)out.Current;
			p_eff[i] = (ssc_number_t)out.Efficiency;
			p_dc[i] = (ssc_number_t)out.Power;
		}
	}