Ejemplo n.º 1
0
Archivo: ketama.c Proyecto: lsm/zir
mcs*
ketama_get_server( char* key, ketama_continuum cont )
{
    unsigned int h = ketama_hashi( key );
    int highp = cont->numpoints;
    mcs (*mcsarr)[cont->numpoints] = cont->array;
    int lowp = 0, midp;
    unsigned int midval, midval1;

    // divide and conquer array search to find server with next biggest
    // point after what this key hashes to
    while ( 1 )
    {
        midp = (int)( ( lowp+highp ) / 2 );

        if ( midp == cont->numpoints )
            return &( (*mcsarr)[0] ); // if at the end, roll back to zeroth

        midval = (*mcsarr)[midp].point;
        midval1 = midp == 0 ? 0 : (*mcsarr)[midp-1].point;

        if ( h <= midval && h > midval1 )
            return &( (*mcsarr)[midp] );

        if ( midval < h )
            lowp = midp + 1;
        else
            highp = midp - 1;

        if ( lowp > highp )
            return &( (*mcsarr)[0] );
    }
}
double MSConnectivityRestraint::unprotected_evaluate(
    DerivativeAccumulator *accum) const {
  IMP_CHECK_OBJECT(ps_.get());
  IMP_OBJECT_LOG;
  tree_.finalize();
  MSConnectivityScore mcs(tree_, ps_.get(), eps_,
                          *const_cast<MSConnectivityRestraint *>(this));
  return mcs.score(accum);
}
Ejemplo n.º 3
0
/**
@todo JSON access errors lack specifier
@todo Check that omegas ar filled/exits
@todo Clean up nested checks for optional JSON arguments
@todo Eigenvalues should be computed independent of json output,
stored and used twice, for screen and file
*/
void run(const Settings &s) {
  // empty configurators
  unique_ptr<csmp::tperm::Configurator> mconf =
      make_unique<csmp::tperm::NullConfigurator>();
  unique_ptr<csmp::tperm::Configurator> fconf =
      make_unique<csmp::tperm::NullConfigurator>();
  // get matrix configurator
  Settings cs(s, "configuration");
  if (cs.json.count("matrix")) {
    Settings mcs(cs, "matrix");
    mconf = MatrixConfiguratorFactory().configurator(mcs);
  }
  // get fracture configurator
  if (cs.json.count("fractures")) {
    Settings fcs(cs, "fractures");
    fconf = FractureConfiguratorFactory().configurator(fcs);
  }
  // get omega generator
  Settings acs(s, "analysis");
  auto ogen = make_omega_generator(acs);
  // load model...
  Settings ms(s, "model");
  auto model = load_model(ms);
  // configure material properties
  mconf->configure(*model);
  fconf->configure(*model);
  // sort boundaries
  auto bds = sort_boundaries(*model, s);
  // ready to solve
  solve(bds, *model);
  // generate omegas
  auto omegas = ogen->generate(*model);
  auto nomegas = named_omegas(omegas);
  // get upscaled tensors
  auto omega_tensors = fetch(*model, nomegas);
  // results
  string jres_fname = "";
  if (s.json.count("output")) {
    Settings outs(s, "output");
    if (outs.json.count("save final binary")) // write to csmp binary
      if (outs.json["save final binary"].get<string>() != "")
        save_model(*model,
                   outs.json["save final binary"].get<string>().c_str());
    if (outs.json.count("vtu")) { // write to vtu
      if (outs.json["vtu"].get<bool>()) {
        make_omega_regions(nomegas, *model);
        vtu(omega_tensors, *model);
      }
      if (outs.json.count("vtu regions"))
        vtu(outs.json["vtu regions"].get<vector<string>>(), *model);
    }
    if (outs.json.count("results file name")) // write to json
      jres_fname = s.json["output"]["results file name"].get<string>();
  }
  report(omega_tensors, *model, jres_fname.c_str());
}
Ejemplo n.º 4
0
int main(int argc, char* argv[])
{
  std::ifstream input((argc>1)?argv[1]:"data/elephant.off");
  Polyhedron tmesh;
  input >> tmesh;
  if (!CGAL::is_triangle_mesh(tmesh))
  {
    std::cout << "Input geometry is not triangulated." << std::endl;
    return EXIT_FAILURE;
  }

  Skeleton skeleton;
  Skeletonization mcs(tmesh);

  // 1. Contract the mesh by mean curvature flow.
  mcs.contract_geometry();

  // 2. Collapse short edges and split bad triangles.
  mcs.collapse_edges();
  mcs.split_faces();

  // 3. Fix degenerate vertices.
  mcs.detect_degeneracies();

  // Perform the above three steps in one iteration.
  mcs.contract();

  // Iteratively apply step 1 to 3 until convergence.
  mcs.contract_until_convergence();

  // Convert the contracted mesh into a curve skeleton and
  // get the correspondent surface points
  mcs.convert_to_skeleton(skeleton);

  std::cout << "Number of vertices of the skeleton: " << boost::num_vertices(skeleton) << "\n";
  std::cout << "Number of edges of the skeleton: " << boost::num_edges(skeleton) << "\n";

  // Output all the edges of the skeleton.
  std::ofstream output("skel-poly.cgal");
  BOOST_FOREACH(Skeleton_edge e, edges(skeleton))
  {
    const Point& s = skeleton[source(e, skeleton)].point;
    const Point& t = skeleton[target(e, skeleton)].point;
    output << "2 "<< s << " " << t << "\n";
  }
  output.close();

  // Output skeleton points and the corresponding surface points
  output.open("correspondance-poly.cgal");
  BOOST_FOREACH(Skeleton_vertex v, vertices(skeleton))
    BOOST_FOREACH(vertex_descriptor vd, skeleton[v].vertices)
      output << "2 " << skeleton[v].point << "  " << get(CGAL::vertex_point, tmesh, vd)  << "\n";

  return EXIT_SUCCESS;
}
Ejemplo n.º 5
0
int main(int argc, char const *argv[]) {
  std::string result;

  result = mcs("a", "b");
  std::cout << (result == "" ? "Works fine" : "Doesnt work") << std::endl;

  result = mcs("aaa", "aba");
  std::cout << (result == "a" ? "Works fine" : "Doesnt work") << std::endl;

  result = mcs("abaca", "abaca");
  std::cout << (result == "abaca" ? "Works fine" : "Doesnt work") << std::endl;

  result = mcs("aaaa", "aa");
  std::cout << (result == "aa" ? "Works fine" : "Doesnt work") << std::endl;

  result = mcs("aa", "aaaa");
  std::cout << (result == "aa" ? "Works fine" : "Doesnt work") << std::endl;

  return 0;
}
Ejemplo n.º 6
0
int main(int argc, char** argv) {
    //int sequence[] = {-5, 4, -6, 3};
    int sequence[] = {-3, 8, -5, -2, 3, 4, -6, 7, 9, 2, 3, -2, 4, -1};
    int sequenceNum = sizeof(sequence)/sizeof(int);
	for(int i = 0; i < sequenceNum; ++i)
		std::cout<<sequence[i]<<" ";
	std::cout<<std::endl;

	Result result;
	mcs(sequence, sequenceNum, result);
	std::cout<<"max_value: "<<result.max_value<<", ["<<result.start<<", "<<result.end<<"]"<<std::endl;

	return 0;
}
ParticlePairsTemp MSConnectivityRestraint::get_connected_pairs() const {
  IMP_CHECK_OBJECT(ps_.get());
  tree_.finalize();
  MSConnectivityScore mcs(tree_, ps_.get(), eps_,
                          *const_cast<MSConnectivityRestraint *>(this));
  EdgeSet edges = mcs.get_connected_pairs();
  ParticlePairsTemp ret(edges.size());
  unsigned index = 0;
  for (EdgeSet::iterator p = edges.begin(); p != edges.end(); ++p) {
    ret[index++] = ParticlePair(mcs.get_particle(p->first),
                                        mcs.get_particle(p->second));
  }
  return ret;
}
Ejemplo n.º 8
0
PY_DEF(pyketama_Continuum_get_points, self, args) {
    PyObject *ret = NULL;
    pyketama_Continuum *pkc = (pyketama_Continuum *)self;

    if (pkc->cont->data->array) {
        int i;
        mcs (*mcsarr)[pkc->cont->data->numpoints] = &pkc->cont->data->array;

        ret = PyList_New(pkc->cont->data->numpoints);
        for (i = 0; i < pkc->cont->data->numpoints; i++) {
            PyList_SET_ITEM(ret, i,
                Py_BuildValue("Is", (*mcsarr)[i].point, (*mcsarr)[i].ip));
        }
    }

    return ret;
}
Ejemplo n.º 9
0
Archivo: ketama.c Proyecto: lsm/zir
void
ketama_print_continuum( ketama_continuum cont )
{
    int a;
    printf( "Numpoints in continuum: %d\n", cont->numpoints );

    if ( cont->array == 0 )
    {
        printf( "Continuum empty\n" );
    }
    else
    {
        mcs (*mcsarr)[cont->numpoints] = cont->array;
        for( a = 0; a < cont->numpoints; a++ )
        {
            printf( "%s (%u)\n", (*mcsarr)[a].ip, (*mcsarr)[a].point );
        }
    }
}
Ejemplo n.º 10
0
    void emit(OutTransport trans) /* TODO const*/ {
        this->buffer_stream.set_out_uint8(this->area_count,
                                          this->offset_area_count);

        this->sdata.emit_end();

        write_packets(
            trans,
            [this](StreamSize<65536+256>, OutStream & sctrl_header) {
                ShareControl_Send(sctrl_header,
                                  PDUTYPE_DATAPDU,
                                  this->userId + GCC::MCS_USERCHANNEL_BASE,
                                  this->buffer_stream.get_offset());

                sctrl_header.out_copy_bytes(this->buffer_stream.get_data(),
                                            this->buffer_stream.get_offset());
            },
            [this](StreamSize<256>, OutStream & sec_header, uint8_t * pkt_data, std::size_t pkt_size) {
                SEC::Sec_Send sec(sec_header,
                                  pkt_data,
                                  pkt_size,
                                  0,
                                  this->encrypt,
                                  this->encryptionLevel);
                (void)sec;
            },
            [this](StreamSize<256>, OutStream & mcs_header, std::size_t pkt_size) {
                MCS::SendDataRequest_Send mcs(static_cast<OutPerStream&>(mcs_header),
                                              this->userId,
                                              GCC::MCS_GLOBAL_CHANNEL,
                                              1,
                                              3,
                                              pkt_size,
                                              MCS::PER_ENCODING);
                (void)mcs;
            },
            [this](StreamSize<256>, OutStream &x224_header, std::size_t pkt_size) {
                X224::DT_TPDU_Send(x224_header, pkt_size);
            }
        );
    }