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);
		}
	}
Пример #2
0
// 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;
}
/*
  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]]));
    }

  }
  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;
            cerr << "table[p] = " << table[p] << endl;
          }
          assert (fabs(v-table[p]) < 0.001);

          SparseVector vec;
          m_featureExtractor.extractFromStateAndAction(vec, board, p, player);
          // for (int i=0; i<vec.size(); i++) {
          //   if (vec[i] > 0 && vec[i] < StandardFeatureExtractor::STATIC_FEATURE_SIZE) {
          //     vec.erase(i);i--;
          //   }
          // }
          for (int i=0; i<featureTable[p].size(); i++) {
            if (featureTable[p][i] > 0 && featureTable[p][i] < 9) {
              featureTable[p].erase(i);i--;
            }
          }
          if (vec.size() != featureTable[p].size()) {
            // cerr << "updated moves:" << endl;
            // for (int i=0; i<staticFeatureUpdateMoves.size(); i++) {
            //   cerr << staticFeatureUpdateMoves[i] << ":" << featureTable[staticFeatureUpdateMoves[i]].toString() << endl;
            // }
            cerr << vec.toString() << endl;
            cerr << featureTable[p].toString() << endl;
            cerr << "point " << p << endl;
            cerr << "turn = " << player << endl;
            cerr << "last move = " << board->getLastMove() << endl;
            cerr << "second last move = " << secondLastMove->m_putPos << endl;
            board->printToErr();
            printProbabilityTableToErr(board);
          }
          assert (vec.size() == featureTable[p].size());
        }
      }
    }
#endif
  }
Пример #5
0
int main(int argc, char **argv) {

	using namespace std;

	
	// Command line input test.
	if (argc!=2) {
		cerr << " Usage: RWSim <input filename>\n";
		exit(1);
	};
	// Input filename in a string.
	string infile(argv[1]);

	//===============================================================
	//=================(Input Parameters)============================
	AgentID nagents;
	long xsize;
	long ysize;
	long geometry=1;
	string in_excluded_file;
	PointSet excluded;
	double ag_threshold;
	double op_threshold=0.5;
	short opinion_topology=2;
	short op_init_method=1;
	double gullibility;
	double standard_dev=0.1;
	long int_range=0;
	int neighbor_type_sg=0;
	long agent_max_speed=1;
	int neighbor_type_movement=1;
	long update_method=1;
	long total_time;

	unsigned long rseed1=1;
	unsigned long rseed2=1;
	long max_rn=1000;
	int convergence_method=1;
	long convergence_check_period=10;
	long convergence_out_period=10;

	bool if_snapshot_out=false;
	string out_snapshot_file;
	long out_snapshot_interval=1;

	bool if_ag_snapshot_out=false;
	string out_ag_snapshot_file;
	int out_ag_snapshot_method=0;
	long out_ag_snapshot_interval=1;

	bool if_sg_snapshot_out=false;
	string out_sg_snapshot_file;
	int out_sg_snapshot_method=0;
	long out_sg_snapshot_interval=1;

	bool if_agent_out=false;
	AgentID agent_id;
	string out_agent_file;
	long out_agent_interval=1;

	bool if_summary_out=false;
	string out_summary_file;

	bool if_network_stat_out=false;
	long out_network_stat_time=-1;
	bool if_components_out=false;
	string out_components_file;

	bool if_agraph_in=false;
	string in_agraph_file;
	short in_agraph_file_format=1;
	short in_agraph_method=0;
	long num_edges;
	double wiring_prob;

	bool if_agents_in=false;
	string in_agents_file;

	//===============================================================
	//==============(Reading Input Parameters)=======================
	cout << "1, Reading the input parameters..." << endl;
	InputParam in1(infile);
	in1.read();
	// in1.print_key_val();
	if (!in1.get("nagents",nagents,cerr)) {
		cerr << "# No parameter given: nagents \n";
		cerr << endl;
		exit(1);
	};
	if (!in1.get("xsize",xsize,cerr)) {
		cerr << "# No parameter given: xsize \n";
		exit(1);
	};
	if (!in1.get("ysize",ysize,cerr)) {
		cerr << "# No parameter given: ysize \n";
		exit(1);
	};
	if (!in1.get("geometry",geometry,cerr)) {
		cerr << "# No parameter given: geometry.";
		cerr << " Default value 1 (regular) will be used.\n";
	};
	if (geometry==2 && \
		!in1.get("in_excluded_file",in_excluded_file,cerr)) {
		cerr << "# No parameter given: in_excluded_file \n";
		exit(1);
	};
	if (!in1.get("gullibility",gullibility,cerr)) {
		cerr << "# No parameter given: gullibility \n";
		exit(1);
	};
	if (gullibility<-epsilon && !in1.get("standard_dev",standard_dev,cerr)) {
		cerr << "# No parameter given: standard_dev \n";
		exit(1);
	};
	if (!in1.get("ag_threshold",ag_threshold,cerr)) {
		ag_threshold=1.0/nagents;
		cerr << "# No parameter given: ag_threshold";
		cerr << ". Default value, 1/nagents=" << ag_threshold;
		cerr << ",  will be used.\n";
	};
	if (!in1.get("op_threshold",op_threshold,cerr)) {
		cerr << "# No parameter given: op_threshold";
		cerr << ". Default value, 0.5" << op_threshold;
		cerr << ",  will be used.\n";
	};
	//if (!in1.get("sg_effect",sg_effect,cerr)) {
	//	cerr << "# No parameter given: sg_effect";
	//	cerr << ". Default value, false, will be used.\n";
	//};
	if (!in1.get("opinion_topology",opinion_topology,cerr)) {
		cerr << "# No parameter given: opinion_topology";
		cerr << ". Default value 2 (circular) will be used.\n";
	};
	if (!in1.get("op_init_method",op_init_method,cerr)) {
		cerr << "# No parameter given: op_init_method";
		cerr << ". Default value 1 (random) will be used.\n";
	};
	if (!in1.get("neighbor_type_sg",neighbor_type_sg,cerr)) {
		cerr << "# No parameter given: neighbor_type_sg";
		cerr << ". Default value 0 (no SG effect) will be used.\n";
	};
	if (!in1.get("int_range",int_range,cerr)) {
		cerr << "# No parameter given: int_range";
		cerr << ". Default value 0 will be used.\n";
	};
	if (!in1.get("agent_max_speed",agent_max_speed,cerr)) {
		cerr << "# No parameter given: agent_max_speed";
		cerr << ". Default value 1 will be used.\n";
	};
	if (!in1.get("neighbor_type_movement",neighbor_type_movement,cerr)) {
		cerr << "# No parameter given: neighbor_type_movement";
		cerr << ". Default value 1 (von Neumann+center) will be used.\n";
	};
	if (!in1.get("update_method",update_method,cerr)) {
		cerr << "# No parameter given: update_method";
		cerr << ". Default value 2 (new) will be used.\n";
	};
	if (!in1.get("total_time",total_time,cerr)) {
		cerr << "# No parameter given: total_time \n";
		exit(1);
	};
	double drseed1, drseed2, dmax=2147483647;
	if (!in1.get("rseed1",drseed1,cerr)) {
		cerr << "# No parameter given: rseed1";
		cerr << ". Default value, " << rseed1 << ", will be used.\n";
	}
	else {
		if (drseed1 < 0) drseed1=-drseed1;
		rseed1=(unsigned long) (drseed1-dmax*((unsigned long) (drseed1/dmax))+0.5);
	};
	if (!in1.get("rseed2",drseed2,cerr)) {
		cerr << "# No parameter given: rseed2";
		cerr << ". Default value, " << rseed2 << ", will be used.\n";
	}
	else {
		if (drseed2 < 0) drseed2=-drseed2;
		rseed2=(unsigned long) (drseed2-dmax*((unsigned long) (drseed2/dmax))+0.5);
	};
	if (!in1.get("max_rn",max_rn,cerr)) {
		cerr << "# No parameter given: max_rn";
		cerr << ". Default value, " << max_rn << ", will be used.\n";
	};
	if (!in1.get("convergence_method",convergence_method,cerr)) {
		cerr << "# No parameter given: convergence_method";
		cerr << ". Default value, 1, will be used.\n";
	};
	if (convergence_method && !in1.get("convergence_check_period",convergence_check_period,cerr)) {
		convergence_check_period=xsize*ysize;
		cerr << "# No parameter given: convergence_check_period.\n";
		cerr << "  Default value, xsize*ysize=" << convergence_check_period;
		cerr << ", will be used.\n";
	};
	if (convergence_method>3 && !in1.get("convergence_out_period",convergence_out_period,cerr)) {
		convergence_out_period=convergence_check_period;
		cerr << "# No parameter given: convergence_out_period.\n";
		cerr << "  Default value, convergence_out_period, " << convergence_check_period;
		cerr << ", will be used.\n";
	};
	if (!in1.get("if_snapshot_out",if_snapshot_out,cerr)) {
		cerr << "# No parameter given: if_snapshot_out";
		cerr << ". Default value, false, will be used.\n";
	};
	if (if_snapshot_out && \
		!in1.get("out_snapshot_file",out_snapshot_file,cerr)) {
		cerr << "# No parameter given: out_snapshot_file \n";
		exit(1);
	};
	if (if_snapshot_out && !in1.get("out_snapshot_interval", \
		out_snapshot_interval,cerr)) {
		cerr << "# No parameter given: out_snapshot_interval";
		cerr << ". Default value 1 will be used.\n";
	};
	if (!in1.get("if_ag_snapshot_out",if_ag_snapshot_out,cerr)) {
		cerr << "# No parameter given: if_ag_snapshot_out";
		cerr << ". Default value, false, will be used.\n";
	};
	if (if_ag_snapshot_out && !in1.get("out_ag_snapshot_file",\
		out_ag_snapshot_file,cerr)) {
		cerr << "# No parameter given: out_ag_snapshot_file \n";
		exit(1);
	};
	if (if_ag_snapshot_out && !in1.get("out_ag_snapshot_method",\
		out_ag_snapshot_method,cerr)) {
		cerr << "# No parameter given: out_ag_snapshot_method";
		cerr << ". Default value 0 will be used.\n";
	};
	if (if_ag_snapshot_out && !in1.get("out_ag_snapshot_interval",\
		out_ag_snapshot_interval,cerr)) {
		cerr << "# No parameter given: out_ag_snapshot_interval";
		cerr << ". Default value 1 will be used.\n";
	};
	if (!in1.get("if_sg_snapshot_out",if_sg_snapshot_out,cerr)) {
		cerr << "# No parameter given: if_sg_snapshot_out";
		cerr << ". Default value, false, will be used.\n";
	};
	if (if_sg_snapshot_out && !in1.get("out_sg_snapshot_file",\
		out_sg_snapshot_file,cerr)) {
		cerr << "# No parameter given: out_sg_snapshot_file \n";
		exit(1);
	};
	if (if_sg_snapshot_out && !in1.get("out_sg_snapshot_method",\
		out_sg_snapshot_method,cerr)) {
		cerr << "# No parameter given: out_sg_snapshot_method";
		cerr << ". Default value 0 will be used.\n";
	};
	if (if_sg_snapshot_out && !in1.get("out_sg_snapshot_interval",\
		out_sg_snapshot_interval,cerr)) {
		cerr << "# No parameter given: out_sg_snapshot_interval";
		cerr << ". Default value 1 will be used.\n";
	};
	if (!in1.get("if_agent_out",if_agent_out,cerr)) {
		cerr << "# No parameter given: if_agent_out";
		cerr << ". Default value, false, will be used.\n";
	};
	if (if_agent_out && !in1.get("agent_id",agent_id,cerr)) {
		cerr << "# No parameter given: agent_id \n";
		exit(1);
	};
	if (if_agent_out && !in1.get("out_agent_file",out_agent_file,cerr)) {
		cerr << "# No parameter given: out_agent_file \n";
		exit(1);
	};
	if (if_agent_out && !in1.get("out_agent_interval",\
		out_agent_interval,cerr)) {
		cerr << "# No parameter given: out_agent_interval";
		cerr << ". Default value 1 will be used.\n";
	};
	if (!in1.get("if_summary_out",if_summary_out,cerr)) {
		cerr << "# No parameter given: if_summary_out";
		cerr << ". Default value, false, will be used.\n";
	};
	if (if_summary_out && !in1.get("out_summary_file",\
		out_summary_file,cerr)) {
		cerr << "# No parameter given: out_summary_file \n";
		exit(1);
	};
	if (if_summary_out && !in1.get("if_network_stat_out",if_network_stat_out,cerr)) {
		cerr << "# No parameter given: if_network_stat_out";
		cerr << ". Default value, false, will be used.\n";
	};
	if (if_summary_out && if_network_stat_out && !in1.get("out_network_stat_time",\
		out_network_stat_time,cerr)) {
		cerr << "# No parameter given: out_network_stat_time";
		cerr << ". Default value, -1, will be used.\n";
	};
	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;
	};