typename vector_assignment_dataset<LA>::record_iterator_type
 vector_assignment_dataset<LA>::begin() const {
   if (nrecords > 0)
     return make_record_iterator(0, &(finite_data[0]), &(vector_data[0]));
   else
     return make_record_iterator(0);
 }
Exemple #2
0
 //////////////////////////////////////////////////////////////////////
 // Basic operations
 self_ptr transform(const transformation& t) const {
   self_ptr new_paths(new self());
   new_paths->reserve(size());
   for (typename base::const_iterator i = begin(); i != end(); ++i)
     new_paths->push_back((*i)->transform(t));
   return new_paths;
 }
int main(int argc, char* argv[]) {
  // Even if using just client calls, we set up a service. Client calls
  // will use the service's io_manager and use it to collect stats
  // automatically.
  ServiceManager service(8 /* num_workers */);
  HTTPService http_service(15000, &service);

  // Open and "fire" N parallel clients.
  const int parallel = 32;
  Client clients[parallel];
  for (int i=0; i<parallel; ++i) {
    ConnectCallback* connect_cb = makeCallableOnce(&Client::start, &clients[i]);
    http_service.asyncConnect("127.0.0.1", 15001, connect_cb);
  }

  // Launch a progress meter in the background. If things hang, let
  // the meter kill this process.
  ProgressMeter meter(&service);
  Callback<void>* progress_cb = makeCallableOnce(&ProgressMeter::check, &meter);
  IOManager* io_manager = service.io_manager();
  io_manager->addTimer(1.0 /*sec*/ , progress_cb);

  // We'd need a '/quit' request to break out of the server.
  // TODO have SIGINT break out nicely as well.
  service.run();

  return 0;
}
Exemple #4
0
/**
 * Constructor of antibodies meta-problem
 *
 * Note: This problem is not intended to be used by itself. Instead use the
 * cstrs_immune_system algorithm if you want to solve constrained problems.
 *
 * @param[in] problem base::problem to be used to set up the boundaries
 * @param[in] method method_type to used for the distance computation.
 * Two posssibililties are available: HAMMING, EUCLIDEAN.
 */
antibodies_problem::antibodies_problem(const base &problem, const algorithm::cstrs_immune_system::distance_method_type method):
	base((int)problem.get_dimension(),
		 problem.get_i_dimension(),
		 problem.get_f_dimension(),
		 0,
		 0,
		 0.),
	m_original_problem(problem.clone()),
	m_pop_antigens(),
	m_method(method)
{
	if(m_original_problem->get_c_dimension() <= 0){
		pagmo_throw(value_error,"The original problem has no constraints.");
	}

	// check that the dimension of the problem is 1
	if(m_original_problem->get_f_dimension() != 1) {
		pagmo_throw(value_error,"The original fitness dimension of the problem must be one, multi objective problems can't be handled with co-evolution meta problem.");
	}

	// encoding for hamming distance
	m_bit_encoding = 25;
	m_max_encoding_integer = int(std::pow(2., m_bit_encoding));

	set_bounds(m_original_problem->get_lb(),m_original_problem->get_ub());
}
Exemple #5
0
// Do gradient descend from multiple starting points
void GradientMatcher::descendFromMultiSPs() {
  printXXMatrWithScore(xx_len_);
  mul_desc_.clear();
  for (int i = 0; i < NUMOFINITDESCENDPOINTS; ++i) {
    mul_desc_.push_back(new MulDesc(n_features_));
  }
  sign_count_.clear();
  sign_count_.resize(n_features_);

  WaitAllDone* waitAllDone = new WaitAllDone();

  finishedCounter = 0;
  for (int ind = 0; ind < NUMOFINITDESCENDPOINTS; ++ind) {
    Person::randWeightsGenerator(mul_desc_[ind]->guessWArr, n_features_);

    Callback<void>* task = makeCallableOnce(&GradientMatcher::feedRandCandsResults,
        this, mul_desc_[ind], 0.001, -1, (double*)NULL);
    thr_pool_->addTask(task);
    // feedRandCandsResults(mul_desc_.back()->guessWArr);
  }
  Callback<void>* allDone = makeCallableOnce(&WaitAllDone::jobsDoneSignal,
      waitAllDone);
  thr_pool_->addTask(allDone);
  waitAllDone->wait();

  std::cerr << "-----------------------------" << "NumFinished: " << finishedCounter
    << std::endl;
  // signCountDowork(mul_desc_.back()->guessWArr, signCounter);
  printSignCounter(sign_count_);
  delete waitAllDone;
}
 /** pass through */ 
 void modify_edge(base* parent, edge_id_t e) {
   vertex_id_t v = g->target(e);
   locks[v].lock();  
   if (basicselector == false) {
     bool t = test_vertex(v);
     bool hasv = has_vertex(v);
     if (hasv && !t) {
       // if test fails, and we currently have the vertex, this is
       // a deletion
       vset[v] = 0;
       numv.dec();
       trigger_all_erase(v);
     } else if (!hasv && t) {
       // if test succeeds, and we currently do not have the vertex,
       // this is an insertion
       vset[v] = 1;
       numv.inc();
       trigger_all_insert(v);
     }
     if (t) trigger_all_modify_edge(e);
   }
   else {
     if (has_vertex(v)) trigger_all_modify_edge(e);
   }
   locks[v].unlock();  
 }
Exemple #7
0
// static
Time Time::FromExploded(bool is_local, const Exploded& exploded)
{
    // 创建系统拆分时间结构, 代表本地时间或者UTC.
    SYSTEMTIME st;
    st.wYear = exploded.year;
    st.wMonth = exploded.month;
    st.wDayOfWeek = exploded.day_of_week;
    st.wDay = exploded.day_of_month;
    st.wHour = exploded.hour;
    st.wMinute = exploded.minute;
    st.wSecond = exploded.second;
    st.wMilliseconds = exploded.millisecond;

    // 转换到FILETIME.
    FILETIME ft;
    if(!SystemTimeToFileTime(&st, &ft))
    {
        NOTREACHED() << "Unable to convert time";
        return Time(0);
    }

    // 确保是UTC.
    if(is_local)
    {
        FILETIME utc_ft;
        LocalFileTimeToFileTime(&ft, &utc_ft);
        return Time(FileTimeToMicroseconds(utc_ft));
    }
    return Time(FileTimeToMicroseconds(ft));
}
Exemple #8
0
 //! Print to the given output stream.
 void print(std::ostream& out) const {
   if (this->size() == 0) {
     out << "[]";
     return;
   } else {
     for (size_type j(0); j < num_cols(); ++j) {
       const dense_vector_view<size_type,size_type>
         col_j_indices(row_indices(j));
       const dense_vector_view<value_type,size_type>
         col_j_values(values(j));
       if (j == 0)
         out << "[";
       else
         out << " ";
       out << "(*," << j << "): ";
       for (size_type i(0); i < col_j_indices.size(); ++i) {
         out << col_j_indices[i] << "(" << col_j_values[i] << ")";
         if (i+1 != col_j_indices.size())
           out << ", ";
       }
       if (j + 1 != num_cols())
         out << "\n";
       else
         out << "]\n";
     }
   }
 } // print
Exemple #9
0
void unipoly::add_to(base &x, base &y)
{
	unipoly& px = x.as_unipoly();
	unipoly py;
	base a;
	INT d1, d2, d3, i;
	
	if (s_kind() != UNIPOLY) {
		cout << "unipoly::add_to() this not a unipoly\n";
		exit(1);
		}
	if (x.s_kind() != UNIPOLY) {
		cout << "unipoly::add_to() x is not a unipoly\n";
		exit(1);
		}
	d1 = degree();
	d2 = px.degree();
	d3 = MAXIMUM(d1, d2);
	
	py.m_l(d3 + 1);
	a = s_i(0);
	a.zero();
	for (i = 0; i <= d1; i++) {
		py[i] = s_i(i);
		}
	for (; i <= d3; i++) {
		py[i] = a;
		}
	for (i = 0; i <= d2; i++) {
		py[i] += px.s_i(i);
		}
	py.swap(y);
}
Exemple #10
0
void unipoly::mult_to(base &x, base &y)
{
	unipoly& px = x.as_unipoly();
	unipoly py;
	base a;
	INT d1, d2, d3, i, j, k;
	
	if (s_kind() != UNIPOLY) {
		cout << "unipoly::mult_to() this not a unipoly\n";
		exit(1);
		}
	if (x.s_kind() != UNIPOLY) {
		cout << "unipoly::mult_to() x is not a unipoly\n";
		exit(1);
		}
	d1 = degree();
	d2 = px.degree();
	d3 = d1 + d2;
	
	py.m_l(d3 + 1);
	a = s_i(0);
	a.zero();
	for (i = 0; i <= d3; i++) {
		py[i] = a;
		}
	for (i = 0; i <= d1; i++) {
		for (j = 0; j <= d2; j++) {
			k = i + j;
			a.mult(s_i(i), px.s_i(j));
			py[k] += a;
			}
		}
	py.swap(y);
}
Exemple #11
0
// static
Time Time::Now()
{
    if(initial_time == 0)
    {
        InitializeClock();
    }

    // 高精度计数器实现计时, 能够得到比10-15ms小的超时. 仅通过
    // CurrentWallclockMicroseconds(), 无法得到细粒度的定时器.
    //
    // 使用时, 初始化时钟(initial_time)和计数器(initial_ctr). 通过
    // 和初始时钟比较能得到消逝的时钟数, 然后就能得出时间差.
    //
    // 为避免误差, 计数器定期的和系统时钟同步.
    while(true)
    {
        TimeTicks ticks = TimeTicks::Now();

        // 计算自开始以来的时间计数.
        TimeDelta elapsed = ticks - initial_ticks;

        // 检查是否需要同步时钟.
        if(elapsed.InMilliseconds() > kMaxMillisecondsToAvoidDrift)
        {
            InitializeClock();
            continue;
        }

        return Time(elapsed + Time(initial_time));
    }
}
Exemple #12
0
 void CosExpression::cacheDerivative(Int withRespectToIndex) const
{
  derivative = ref<ExpressionNode>( NewObj NegateExpression(ref<ExpressionNode>( 
					NewObj ProductExpression( ref<ExpressionNode>(NewObj SinExpression(arg)),
                                                                  arg->differentiate(withRespectToIndex)) ) ) ); 
  derivWithRespToIndex = withRespectToIndex;
  derivCached = true;
}
 void vector_assignment_dataset<LA>::set_record(size_t i, const assignment& a, double w) {
   assert(i < nrecords);
   convert_finite_assignment2record(a.finite(), finite_data[i]);
   convert_vector_assignment2record(a.vector(), vector_data[i]);
   data_vector[i].clear();
   foreach(finite_variable* v, finite_seq) {
     finite_assignment::const_iterator it(a.finite().find(v));
     assert(it != a.finite().end());
     data_vector[i].finite()[v] = it->second;
   }
Exemple #14
0
/**
 * Constructor using initial constrained problem
 *
 * @param[in] problem base::problem to be modified to use a constrained to
 * multi-objective handling technique.
 * @param[in] method method_type to be modified to use a single constrained
 * to multi-objective approach defined with OBJ_CSTRS, OBJ_CSTRSVIO or OBJ_EQVIO_INEQVIO
 *
 */
con2mo::con2mo(const base &problem, const method_type method):
		base_meta(
		 problem,
		 problem.get_dimension(),
		 problem.get_i_dimension(),
		 __mo_dimension__(problem, method),
		 0,
		 0,
		 std::vector<double>()),
	m_method(method)
{}
Exemple #15
0
void hollerith::copyobject_to(base &x)
{
#ifdef HOLLERITH_COPY_VERBOSE
	cout << "in hollerith::copyobject_to()\n";
#endif
	x.freeself();
	hollerith & xx = x.change_to_hollerith();
	if (s() == NULL)
		return;
	xx.init(s());
}
Exemple #16
0
 //! Return a const view of column j of the matrix.
 sparse_vector_view<value_type,size_type> col(size_type j) const {
   if (j < num_cols()) {
     size_type co_j = col_offsets_[j];
     size_type co_jp1 = col_offsets_[j+1];
     return sparse_vector_view<value_type,size_type>
       (num_rows(), co_jp1 - co_j, row_indices_.begin() + co_j,
        values_.begin() + co_j);
   } else {
     return sparse_vector_view<value_type,size_type>();
   }
 }
Exemple #17
0
void number_partition::copyobject_to(base &x)
{
#ifdef PARTITION_COPY_VERBOSE
	cout << "number_partition::copyobject_to()\n";
	print_as_vector(cout);
#endif
	Vector::copyobject_to(x);
	x.as_number_partition().settype_number_partition();
#ifdef PARTITION_COPY_VERBOSE
	x.as_number_partition().print_as_vector(cout);
#endif
}
Exemple #18
0
void unipoly::normalize(base &p)
{
	if (p.s_kind() != UNIPOLY) {
		cout << "unipoly::normalize() p not an UNIPOLY" << endl;
		exit(1);
		}
	unipoly p1 = p.as_unipoly();
	unipoly q, r;
	
	integral_division(p1, q, r, 0); 
	swap(r);
}
Exemple #19
0
void unipoly::copyobject_to(base &x)
{
#ifdef COPY_VERBOSE
	cout << "unipoly::copyobject_to()\n";
	print_as_vector(cout);
#endif
	Vector::copyobject_to(x);
	x.as_unipoly().settype_unipoly();
#ifdef COPY_VERBOSE
	x.as_unipoly().print_as_vector(cout);
#endif
}
Exemple #20
0
INT hollerith::compare_with(base &a)
{
	BYTE *p1, *p2;
	
	if (a.s_kind() != HOLLERITH) {
		cout << "hollerith::compare_with() a is not a hollerith object" << endl;
		exit(1);
		}
	p1 = s();
	p2 = a.as_hollerith().s();
	return strcmp(p1, p2);
}
Exemple #21
0
void geometry::copyobject_to(base &x)
{
#ifdef GEOMETRY_COPY_VERBOSE
	cout << "geometry::copyobject_to()\n";
	print_as_vector(cout);
#endif
	Vector::copyobject_to(x);
	x.as_geometry().settype_geometry();
#ifdef GEOMETRY_COPY_VERBOSE
	x.as_geometry().print_as_vector(cout);
#endif
}
Exemple #22
0
void base::copyobject_to(base &x)
{
	kind k = s_kind();
	OBJECTSELF s = self;
	
	if (k != BASE) {
		cout << "error: base::copyobject_to() for object of kind " << kind_ascii(k) << endl;
		exit(1);
		}
	cout << "warning: base::copyobject_to() for object: " << *this << "\n";
	x.freeself();
	x.c_kind(k);
	x.self = s;
}
Exemple #23
0
base::base(const base &x)
	// copy constructor:    this := x
{
	// cout << "base::copy constructor for object: " << x << "\n";
	clearself();
#if 0
	if (x.k != x.s_virtual_kind()) {
		x.c_kind(k);
		}
#endif
	// cout << "base::copy constructor, calling copyobject_to()\n";
	const_cast<base &>(x).copyobject_to(*this);
	// cout << "base::copy constructor finished\n";
}
Exemple #24
0
void base::swap(base &a)
{
	kind k, ka;
	OBJECTSELF s, sa;
	
	k = s_kind();
	ka = a.s_kind();
	s = self;
	sa = a.self;
	c_kind(ka);
	self = sa;
	a.c_kind(k);
	a.self = s;
}
Exemple #25
0
 //! Return a const view of the row indices for column j.
 const dense_vector_view<size_type,size_type>
 row_indices(size_type j) const {
   assert(j < num_cols());
   return dense_vector_view<size_type,size_type>
     (col_offsets_[j+1] - col_offsets_[j],
      row_indices_.begin() + col_offsets_[j]);
 }
Exemple #26
0
	static void
	manage(any_storage& d, const any_storage& s, any_ops::op_code op)
	{
		switch(op)
		{
		case equals:
			{
				const auto p(d.access<any_storage*>());

				d.access<bool>() = get_reference(*p) == get_reference(s);
			}
			break;
		default:
			base::manage(d, s, op);
		}
	}
Exemple #27
0
void Spinner::Private::Draw(const Context &context) {
  angle += 5.f;
  if (angle > 360.f) angle = 0.f;

  Canvas *canvas = context.canvas();
  int scale = context.surface()->GetScale();
  canvas->Scale(scale, scale);

  const RectF &rect = proprietor()->GetBounds();
  float radius = base::Clamp(std::min(rect.width(), rect.height()) / 2.f - 50.f,
                             50.f, 200.f);

  Paint paint;
  paint.SetAntiAlias(true);

  paint.SetColor(background);
  paint.SetStyle(Paint::Style::kStyleFill);
  canvas->DrawRect(rect, paint);

  paint.SetColor(ColorF(foreground));
  paint.SetStyle(Paint::Style::kStyleStroke);
  paint.SetStrokeWidth(6.f);

  canvas->DrawArc(RectF(rect.center_x() - radius,
                        rect.center_y() - radius,
                        rect.center_x() + radius,
                        rect.center_y() + radius),
                  angle, 300.f, false, paint);

  frame_callback.Setup(context.surface());
}
KVService::KVService(int port, ServiceManager* service_manager)
  : service_manager_(service_manager),
    stats_(service_manager->num_workers()),
    lf_hashtable_(service_manager->num_workers()) {
  AcceptCallback* cb = makeCallableMany(&KVService::acceptConnection, this);
  service_manager_->registerAcceptor(port, cb);
}
bool
PluginModuleParent::ShouldContinueFromReplyTimeout()
{
#ifdef MOZ_CRASHREPORTER
    CrashReporterParent* crashReporter = CrashReporter();
    if (crashReporter->GeneratePairedMinidump(this)) {
        mBrowserDumpID = crashReporter->ParentDumpID();
        mPluginDumpID = crashReporter->ChildDumpID();
        PLUGIN_LOG_DEBUG(
                ("generated paired browser/plugin minidumps: %s/%s (ID=%s)",
                 NS_ConvertUTF16toUTF8(mBrowserDumpID).get(),
                 NS_ConvertUTF16toUTF8(mPluginDumpID).get(),
                 NS_ConvertUTF16toUTF8(crashReporter->HangID()).get()));
    } else {
        NS_WARNING("failed to capture paired minidumps from hang");
    }
#endif

    // this must run before the error notification from the channel,
    // or not at all
    MessageLoop::current()->PostTask(
        FROM_HERE,
        mTaskFactory.NewRunnableMethod(
            &PluginModuleParent::CleanupFromTimeout));

    if (!KillProcess(OtherProcess(), 1, false))
        NS_WARNING("failed to kill subprocess!");

    return false;
}
Exemple #30
0
 //! Return the maximum number of non-zeros in any column.
 size_type max_non_zeros_per_column() const {
   size_type k(0);
   for (size_type j(0); j < num_cols(); ++j) {
     k = max(k, col_offsets_[j+1] - col_offsets_[j]);
   }
   return k;
 }