当前位置: 首页>>代码示例>>C++>>正文


C++ PointSet::insert方法代码示例

本文整理汇总了C++中PointSet::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ PointSet::insert方法的具体用法?C++ PointSet::insert怎么用?C++ PointSet::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PointSet的用法示例。


在下文中一共展示了PointSet::insert方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: frommxArray

	inline void frommxArray(const mxArray *ParamArray) {
		/*
		 * This function expects the ParamArray to be a MATLAB structure with 
		 * at-least the following fields
		 * 
		 *   a - single - scalar
		 *   b - single - scalar
		 *   c - single - scalar
		 *   d - single - scalar
		 *   
		 *   GridXSpec - single - vector of length 3
		 *   GridYSpec - single - vector of length 3
		 *   
		 *   GridXSpec = [GridXBegin, GridXStep, GridXEnd]
		 *   GridYSpec = [GridYBegin, GridYStep, GridYEnd]
		 *
		 *   onemsbyTstep - uint32_t - scalar
		 *
		 *   InitialPointSet - should be a valid 'PointVector' struct representing
		 *                     the region of points from which to search ahead.
		 */
		getInputfromStruct<float>(ParamArray, "a", this->a, getInputOps(2, "is_required", "required_size", 1));
		getInputfromStruct<float>(ParamArray, "b", this->b, getInputOps(2, "is_required", "required_size", 1));
		getInputfromStruct<float>(ParamArray, "c", this->c, getInputOps(2, "is_required", "required_size", 1));
		getInputfromStruct<float>(ParamArray, "d", this->d, getInputOps(2, "is_required", "required_size", 1));

		uint32_t onemsbyTstep;
		getInputfromStruct<uint32_t>(ParamArray, "onemsbyTstep", onemsbyTstep, getInputOps(2, "is_required", "required_size", 1));

		MexVector<float> GridXSpec;
		MexVector<float> GridYSpec;

		getInputfromStruct<float>(ParamArray, "GridXSpec", GridXSpec, getInputOps(2, "is_required", "required_size", 3));
		getInputfromStruct<float>(ParamArray, "GridYSpec", GridYSpec, getInputOps(2, "is_required", "required_size", 3));

		float eps = 1E-10; // epsilon used for floating point comparisons
		uint32_t XGridMax, YGridMax;
		XGridMax = uint32_t((GridXSpec[2] - GridXSpec[0])/GridXSpec[1] + 2*eps) + 1;// largest n such that (n-1)*GridXSpec[1] + GridXSpec[0] <= GridXSpec[2]
		YGridMax = uint32_t((GridYSpec[2] - GridYSpec[0])/GridYSpec[1] + 2*eps) + 1;// largest n such that (n-1)*GridYSpec[1] + GridYSpec[0] <= GridYSpec[2]

		this->PrivateTransform.scaleX = GridXSpec[1];
		this->PrivateTransform.scaleY = GridYSpec[1];
		this->PrivateTransform.shiftX = GridXSpec[0];
		this->PrivateTransform.shiftY = GridYSpec[0];

		this->XRange = {0, XGridMax};
		this->YRange = {0, YGridMax};

		this->timeStep = 1.0f / onemsbyTstep;

		// Calculate the Grid Y Coordinate for 30.0V
		auto GridY30V = this->Transform.toGridCoords(SinglePoint(0, 30.0f)).y;
		GridY30V = (GridY30V >= YGridMax)? YGridMax : GridY30V;
		for(uint32_t i=0; i < XGridMax; ++i) {
			Point gridPoint(i, uint32_t(GridY30V+0.5f));
			PrivateInitialPointSet.insert(gridPoint);
		}
	}
开发者ID:maharjun,项目名称:GetAttractionBasin,代码行数:58,代码来源:SimpleIzhikevichSpiking.hpp

示例2: testScalability

// Create a randomly generated point
// scatter time execution
void testScalability(unsigned numpts)
{
    using namespace boost;
    using namespace std;

    typedef adjacency_matrix<undirectedS, no_property,
        property <edge_weight_t, double,
        property<edge_index_t, int> > > Graph;
    typedef graph_traits<Graph>::vertex_descriptor Vertex;
    typedef property_map<Graph, edge_weight_t>::type WeightMap;
    typedef set<simple_point<double>, cmpPnt<double> > PointSet;
    typedef vector< Vertex > Container;

    boost::mt19937 rng(time(0));
    uniform_real<> range(0.01, (numpts * 2));
    variate_generator<boost::mt19937&, uniform_real<> >
        pnt_gen(rng, range);

    PointSet points;
    simple_point<double> pnt;

    while (points.size() < numpts)
    {
        pnt.x = pnt_gen();
        pnt.y = pnt_gen();
        points.insert(pnt);
    }

    Graph g(numpts);
    WeightMap weight_map(get(edge_weight, g));
    vector<simple_point<double> > point_vec(points.begin(), points.end());

    connectAllEuclidean(g, point_vec, weight_map, get(vertex_index, g), numpts);

    Container c;
    timer t;
    double len = 0.0;

    // Run the TSP approx, creating the visitor on the fly.
    metric_tsp_approx(g, make_tsp_tour_len_visitor(g, back_inserter(c), len, weight_map));

    cout << "Number of points: " << num_vertices(g) << endl;
    cout << "Number of edges: " << num_edges(g) << endl;
    cout << "Length of tour: " << len << endl;
    cout << "Elapsed: " << t.elapsed() << endl;
}
开发者ID:LancelotGHX,项目名称:Simula,代码行数:48,代码来源:metric_tsp_approx.cpp

示例3: initProbabilities

/*
  void SoftmaxPolicyPlayout::initProbabilities(const Go::Board *init_board) {
    //memset(m_probTableBlack, 0, sizeof(double)*MAX_BOARD_SIZE);
    //memset(m_probTableWhite, 0, sizeof(double)*MAX_BOARD_SIZE);

    //SparseVector extractedFeatures;
    Color turns[] = {BLACK, WHITE};
    double *tables[2] = {m_probTableBlack, m_probTableWhite};
    SparseVector *featureTables[2] = {m_featureTableBlack, m_featureTableWhite};

    for (int i=0; i<2 && tables[i] != NULL; i++) {
      Color myTurn = turns[i];

      initProbabilities(init_board, myTurn, tables[i], featureTables[i]);
    }
  }
*/
  void SoftmaxPolicyPlayout::initProbabilities(const Go::Board *init_board, Color myTurn, double *table, SparseVector *featureTable) {
    Color enemyTurn = Board::flipColor(myTurn);
    PointSet &updatedMoves = myTurn == BLACK ? m_toResetStaticFeaturesMovesBlack : m_toResetStaticFeaturesMovesWhite;
    updatedMoves.clear();

    for (int y=0; y<init_board->getSize(); y++) {
      for (int x=0; x<init_board->getSize(); x++) {
        featureTable[init_board->xyToPoint(x,y)].clear();
      }
    }

    PointSet legalMovesSet;

    // update pattern features
    for (int y=0; y<init_board->getSize(); y++) {
      for (int x=0; x<init_board->getSize(); x++) {
        Point p = init_board->xyToPoint(x,y);
        if (init_board->isColor(p, FREE) &&
            (init_board->getNeighborEmptyCount(p)>=1 || init_board->checkLegalHand(p, myTurn, enemyTurn) == Board::PUT_LEGAL)) {
          m_featureExtractor.updatePatternFeature(featureTable[p], init_board, p, myTurn);
          legalMovesSet.insert(p,p);
        } else {
          // prob is 0
          //featureTable[p].clear();
          if (init_board->isColor(p, FREE)) {
            m_featureExtractor.updatePatternFeature(featureTable[p], init_board, p, myTurn);
          }
          table[p] = 0;
        }
      }
    }

    // update static features
    m_featureExtractor.updateStaticFeaturesForAllMovesWithoutClearOldFeatures(init_board, myTurn, legalMovesSet, featureTable, updatedMoves);
    
    for (size_t i=0; i<legalMovesSet.size(); i++) {
      //table[legalMovesSet[i]] = m_expFeatureWeights.multiplyAll(featureTable[legalMovesSet[i]]);
      table[legalMovesSet[i]] = fmath::expd(m_featureWeights.dot(featureTable[legalMovesSet[i]]));
      //table[legalMovesSet[i]] = exp(m_featureWeights.dot(featureTable[legalMovesSet[i]]));
    }

  }
开发者ID:omochi64,项目名称:ComputerGO_MCTS,代码行数:59,代码来源:SoftmaxPolicyPlayout.cpp

示例4: updateProbabilitiesBeforeAction

  void SoftmaxPolicyPlayout::updateProbabilitiesBeforeAction(const Go::Board *board, Color player) {
    // check the last move
    size_t historySize = board->getHistoryCount();
    const Board::MoveChangeEntry *lastMove = board->getHistory(historySize-1);       // enemy's move
    const Board::MoveChangeEntry *secondLastMove = board->getHistory(historySize-2); // last my move
    const Board::MoveChangeEntry *thirdLastMove = board->getHistory(historySize-3);

    double *table = NULL;
    SparseVector *featureTable = NULL;
    if (player == BLACK) {
      table = m_probTableBlack;
      featureTable = m_featureTableBlack;
    } else {
      table = m_probTableWhite;
      featureTable = m_featureTableWhite;
    }

    if (lastMove && lastMove->m_putPos != PASS) table[lastMove->m_putPos] = 0;
    if (secondLastMove && secondLastMove->m_putPos != PASS) table[secondLastMove->m_putPos] = 0;

    PointSet updatedMoves;

    // reset static features which are set in the last time of player
    PointSet &previousSetMoves = player == BLACK ? m_toResetStaticFeaturesMovesBlack : m_toResetStaticFeaturesMovesWhite;
    for (size_t i=0; i<previousSetMoves.size(); i++) {
      //cerr << previousSetMoves[i] << ":" << featureTable[previousSetMoves[i]].toString() << endl;
      Point p = previousSetMoves[i];
      StandardFeatureExtractor::clearStaticFeatures(featureTable[p]);
      if (board->isColor(p, FREE) && 
          (board->getNeighborEmptyCount(p) >= 1 || board->checkLegalHand(p, player, Board::flipColor(player)) == Board::PUT_LEGAL)) {
        updatedMoves.insert(p,p);
      }
    }
    previousSetMoves.clear();

    // enumerate pattern update moves
    PointSet patternUpdateMoves;
    enumerateMovesOfPatternChanged(patternUpdateMoves, board, player, lastMove, secondLastMove, false);

    // enumerate moves that their status will change
    PointSet toBeLegal, toBeIllegal;
    PointSet legalMovesSet;
    toBeLegal.clear(); toBeIllegal.clear();
    enumerateToBeLegalAndIllegalMoves(board, table, player, toBeLegal, toBeIllegal, legalMovesSet, false);

    PointSet &staticFeatureUpdateMoves = previousSetMoves;

    if (lastMove == NULL) return; // no further old moves

    // update static features
    m_featureExtractor.updateStaticFeaturesForAllMovesWithoutClearOldFeatures(board, player, legalMovesSet, featureTable, staticFeatureUpdateMoves);

    // update patterns
    PointSet::ListConstIterator it, end = patternUpdateMoves.end();
    for (it = patternUpdateMoves.begin(); it!=end; it++) {
      SparseVector &targetFeatures = featureTable[*it];
      assert (board->isColor(*it, FREE));
      m_featureExtractor.updatePatternFeature(targetFeatures, board, *it, player);
      //if (board->checkLegalHand(*it, player, Board::flipColor(player)) == Board::PUT_LEGAL) {
      if ((!toBeIllegal.contains(*it) && table[*it] != 0) || toBeLegal.contains(*it)) {
        updatedMoves.insert(*it,*it);
      }
    }

    end = toBeLegal.end();
    for (it = toBeLegal.begin(); it!=end; it++) {
      updatedMoves.insert(*it,*it);
      // check capturing, atari features
    }

    end = staticFeatureUpdateMoves.end();
    for (it=staticFeatureUpdateMoves.begin(); it!=end; it++) {
      //table[*it] = m_expFeatureWeights.multiplyAll(featureTable[*it]);
      updatedMoves.insert(*it,*it);
    }

    end = updatedMoves.end();
    for (it=updatedMoves.begin(); it!=end; it++) {
      //table[*it] = m_expFeatureWeights.multiplyAll(featureTable[*it]);
      table[*it] = fmath::expd(m_featureWeights.dot(featureTable[*it]));
      //table[*it] = exp(m_featureWeights.dot(featureTable[*it]));
    }

    end = toBeIllegal.end();
    for (it = toBeIllegal.begin(); it!=end; it++) {
      table[*it] = 0;
      StandardFeatureExtractor::clearStaticFeatures(featureTable[*it]);
    }

#ifdef STRICT_CHECK
    for (int y=0; y<board->getSize(); y++) {
      for (int x=0; x<board->getSize(); x++) {
        Point p = board->xyToPoint(x,y);
        Board::PutType err = board->checkLegalHand(p, player, Board::flipColor(player));
        assert (!(err == Board::PUT_LEGAL && table[p] == 0) &&
                !(err != Board::PUT_LEGAL && table[p] != 0));
        if (err == Board::PUT_LEGAL) {
          double v = m_expFeatureWeights.multiplyAll(featureTable[p]);
          if (fabs(v-table[p]) >= 0.001) {
            cerr << "v = " << v << endl;
//.........这里部分代码省略.........
开发者ID:omochi64,项目名称:ComputerGO_MCTS,代码行数:101,代码来源:SoftmaxPolicyPlayout.cpp

示例5: main


//.........这里部分代码省略.........
	if (if_summary_out && if_network_stat_out && !in1.get("if_components_out",if_components_out,cerr)) {
		cerr << "# No parameter given: if_components_out";
		cerr << ". Default value, false, will be used.\n";
	};
	if (if_summary_out && if_network_stat_out && if_components_out && !in1.get("out_components_file",\
		out_components_file,cerr)) {
		cerr << "# No parameter given: out_components_file \n";
		exit(1);
	};
	if (!in1.get("if_agraph_in",if_agraph_in,cerr)) {
		if_agraph_in=false;
		cerr << "# No parameter given: in_agraph_in.";
		cerr << "  Default value, false, will be used.\n";
	};
	if (if_agraph_in) {
		if (in1.get("in_agraph_file",in_agraph_file,cerr)) {
			if (!Util::if_file(in_agraph_file)) {
				cerr << "# File, " << in_agraph_file << ", doesn't exist.";
				cerr << "  AG will be created randomly.\n";
				if_agraph_in=false;
			};
		}
		else {
			cerr << "# No parameter given: in_agraph_file.";
			cerr << "  AG will be created randomly.\n";
			if_agraph_in=false;
		};
	};
	if (if_agraph_in && !in1.get("in_agraph_file_format",in_agraph_file_format,cerr)) {
		cerr << "# No parameter given: in_agraph_file_format.";
		cerr << "  Default value, 1, will be used.\n";
	};
	if (!if_agraph_in && !in1.get("num_edges",num_edges,cerr)) {
		cerr << "# No parameter given: num_edges \n";
		exit(1);
	};
	if (!in1.get("wiring_prob",wiring_prob,cerr) && ((!if_agraph_in && num_edges<0) || update_method>=3)) {
		cerr << "# No parameter given: wiring_prob \n";
		exit(1);
	};
	if (!if_agraph_in && !in1.get("in_agraph_method",in_agraph_method,cerr)) {
		cerr << "# No parameter given: in_agraph_method \n";
		exit(1);
	};
	if (!in1.get("if_agents_in",if_agents_in,cerr)) {
		if_agents_in=false;
		cerr << "# No parameter given: in_agents_in.";
		cerr << "  Default value, false, will be used.\n";
	};
	if (if_agents_in) {
		if (in1.get("in_agents_file",in_agents_file,cerr)) {
			if (!Util::if_file(in_agents_file)) {
				cerr << "# File, " << in_agents_file << ", doesn't exist.";
				cerr << "  Agents will be created randomly.\n";
				if_agents_in=false;
			};
		}
		else {
			cerr << "# No parameter given: in_agents_file.";
			cerr << "  Agents will be created randomly.\n";
			if_agents_in=false;
		};
	};
	
	// close the input parameter file.
	in1.close();

	// Checking values of basic input parameters
	Util::error_check(nagents,xsize,ysize,gullibility,standard_dev,\
		ag_threshold, op_threshold,opinion_topology,op_init_method,neighbor_type_sg,agent_max_speed,\
		(!if_agraph_in && num_edges<0 ? wiring_prob : 0.5),total_time,\
		(if_agraph_in ? 0 : num_edges),rseed1,rseed2,max_rn);

	cout << "\tNumber of agents: " << nagents << endl;

	// Assigning the size of the grid.
	if (geometry==0) { // special case of 1d ring.
		xsize=nagents;
		ysize=1;
		gullibility=1;
		neighbor_type_sg=1;
		agent_max_speed=0;
		neighbor_type_movement=1;
		cout << "\tSpecial case of 1D ring with no agent movement." << endl;
	};
	Point::set_size(xsize,ysize); 
	cout << "\tGrid size: " << Point::get_xsize() << " and " << Point::get_ysize() << endl;
	if (geometry==2) {
		std::ifstream ifile;
		ifile.open(in_excluded_file.c_str(),ios::in);
		if (!ifile) {
			cerr << "# Error: Input file, " << in_excluded_file;
			cerr << ", doesn't exist.\n";
			exit(1);
		};
		long x, y;
		while (ifile >> x >> y && x>=0 && x<xsize && y>=0 && y<ysize) excluded.insert(Point(x,y));
		ifile.close();
		cout << "\t(Total of " << excluded.size() << " points will be excluded.)" << endl;
	};
开发者ID:suhanree,项目名称:OpinionNetwork,代码行数:101,代码来源:RWMain.C


注:本文中的PointSet::insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。