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


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

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


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

示例1: invade_bond

bool invade_bond(Bond & inv_bond, double strength)
{
	Site invSite = inv_bond.second;
	if (invadedSites.count(invSite) > 0){
		removed.push_back(std::make_pair(strength,inv_bond));
		return true;
	}


	double newStrength;
	Site newNeighbor;
	Bond newBond;
	growth.push_back(std::make_pair(strength,inv_bond));
	invadedSites.insert(invSite);
	for (int dir=0;dir<4;++dir)
	{
		newNeighbor = get_neighbor(invSite, dir);
		if (invadedSites.count(newNeighbor) == 0)
		{
			newStrength = get_new_strength(dir);
			if(newStrength < 1.0 || accessibleBonds.size() < 10000)
			{
				newBond = std::make_pair(invSite, newNeighbor);
				accessibleBonds.insert(std::make_pair(newStrength, newBond));
			}
		}
	}
	return false;
}
开发者ID:jqnorris,项目名称:Misc,代码行数:29,代码来源:simulation.cpp

示例2: invade_bond

bool invade_bond(Bond & inv_bond)
{
	Site invSite = inv_bond.second.second;
	if (invadedSites.count(invSite) > 0){
		trapped.push_back(inv_bond);
		return true;
	}


	double newStrength;
	Site newNeighbor;
	Bond newBond;
	growth.push_back(inv_bond);
	invadedSites.insert(invSite);
    for (int dir=0; dir<6; dir++)
    {
    	newNeighbor = get_neighbor(invSite, dir);
    	if (invadedSites.count(newNeighbor) == 0)
    	{
    		newStrength = drand48();
       		newBond = std::make_pair(newStrength, std::make_pair(invSite, newNeighbor));
        	accessibleBonds.insert(std::make_pair(newStrength, newBond));
    	}
    }
    return false;
}
开发者ID:jqnorris,项目名称:InvasionPercolation,代码行数:26,代码来源:IP_3D.cpp

示例3: initialize_sim

void initialize_sim(void)
{
	Site start = std::make_pair(0, 0);
	invadedSites.insert(start);
	for (int neigh=0;neigh<4; neigh++)
	{
		Bond newBond;
		double newStrength =get_new_strength(neigh);
		newBond = std::make_pair(start, get_neighbor(start, neigh));
		accessibleBonds.insert(std::make_pair(newStrength, newBond));
	}
}
开发者ID:jqnorris,项目名称:Misc,代码行数:12,代码来源:simulation.cpp

示例4: main

int main(int argc, char **argv)
{
	long int i, N;
	bool already_invaded;

	z = atoi(argv[1]);
	N = atoi(argv[2]);

    Site start = -1;
    invadedSites.insert(start);
    for (int dir=0; dir<z; ++dir)
    {
    		double newStrength = drand48();
			Site newNeighbor = 3*(start+1)+dir;
       		Bond newBond = std::make_pair(newStrength, std::make_pair(start, newNeighbor));
        	accessibleBonds.insert(std::make_pair(newStrength, newBond));
    }

    for (i=0; i<N;)
    {
    	BondMap::iterator weakest;
    	weakest = accessibleBonds.begin();
    	already_invaded = invade_bond(weakest->second);
    	if(!already_invaded)
    	{
    		i++;
    	}
    	accessibleBonds.erase(weakest);
    }

	std::ofstream toFile1("fractures.txt", std::ios::trunc);
	toFile1 << growth.size() << "\n";
	toFile1 << "Invasion for: temp" << "\n";
	toFile1.precision(17);

	Bond current_Line;
	while (!growth.empty())
	{
		current_Line = growth.front();
		growth.pop_front();
		toFile1 << current_Line.first << "\t";
		toFile1 << current_Line.second.first << "\t";
		toFile1 << current_Line.second.second<< "\n";
	}

	  toFile1.close();

    return 0;
}
开发者ID:jqnorris,项目名称:InvasionPercolation,代码行数:49,代码来源:IP_BetheLattice.cpp

示例5: invade_bond

void invade_bond(Bond & inv_bond)
{
	Site invSite = inv_bond.second.second;

	double newStrength;
	double tempWeight = inv_bond.first;
	Site newNeighbor;
	Bond newBond;
	growth.push_back(inv_bond);

	std::deque<Bond> tempList;

    for (int dir=0;dir<4;++dir)
    {
    	newNeighbor = get_neighbor(invSite, dir);
    	if (invadedSites.count(newNeighbor) == 0)
    	{
    		newStrength = drand48();
    		tempWeight += newStrength;
        	newBond = std::make_pair(newStrength, std::make_pair(invSite, newNeighbor));
        	tempList.push_back(newBond);
    	}
    }

    invSite.weight = tempWeight;
    invadedSites.insert(invSite);
    if(invSite.weight < threshold)
    {
    	while (!tempList.empty())
		{
    		newBond = tempList.front();
    		tempList.pop_front();
    		accessibleBonds.insert(std::make_pair(newBond.first, newBond));
		}
    }
    else
    {
    	while (!tempList.empty())
    	{
    	    newBond = tempList.front();
    	    tempList.pop_front();
    	    trapped.push_back(newBond);
    	}
    };
}
开发者ID:jqnorris,项目名称:InvasionPercolation,代码行数:45,代码来源:simulation.cpp

示例6: invade_bond

bool invade_bond(Bond & inv_bond)
{
	Site invSite = inv_bond.second.second;

	double newStrength;
	Site newNeighbor;
	Bond newBond;
	growth.push_back(inv_bond);
	invadedSites.insert(invSite);
    for (int dir=0; dir<z-1; ++dir)
    {
    		newStrength = drand48();
			newNeighbor = 3*(invSite+1)+dir;
       		newBond = std::make_pair(newStrength, std::make_pair(invSite, newNeighbor));
        	accessibleBonds.insert(std::make_pair(newStrength, newBond));
    }
    return false;
}
开发者ID:jqnorris,项目名称:InvasionPercolation,代码行数:18,代码来源:IP_BetheLattice.cpp

示例7: main

int main(int argc, char **argv)
{
	long int i, N;
	bool already_invaded;

	N = atoi(argv[1]);
    Site start = std::make_tuple(0, 0, 0);
    invadedSites.insert(start);
    for (int neigh=0;neigh<4; neigh++)
    {
    	Bond newBond;
    	double newStrength = drand48();
    	newBond = std::make_pair(newStrength, std::make_pair(start, get_neighbor(start, neigh)));
    	accessibleBonds.insert(std::make_pair(newStrength, newBond));
    }

    for (i=0; i<N;)
    {
    	BondMap::iterator weakest;
    	weakest = accessibleBonds.begin();
    	already_invaded = invade_bond(weakest->second);
    	if(!already_invaded)
    	{
    		i++;
    	}
    	accessibleBonds.erase(weakest);
    }

	std::ofstream toFile1("fractures.txt", std::ios::trunc);
	std::ofstream toFile2("trapped.txt", std::ios::trunc);
	toFile1 << growth.size() << "\n";
	toFile2 << trapped.size() << "\n";
	toFile1 << "Invasion for: temp" << "\n";
	toFile2 << "Trapping for: temp" << "\n";
	toFile1.precision(17);
	toFile2.precision(17);

	Bond current_Line;
	while (!growth.empty())
	{
		current_Line = growth.front();
		growth.pop_front();
		toFile1 <<  current_Line.first << "\t";
		toFile1 <<  std::get<0>(current_Line.second.first) << "\t";
		toFile1 <<  std::get<1>(current_Line.second.first) << "\t";
		toFile1 <<  std::get<2>(current_Line.second.first) << "\t";
		toFile1 <<  std::get<0>(current_Line.second.second) << "\t";
		toFile1 <<  std::get<1>(current_Line.second.second) << "\t";
		toFile1 <<  std::get<2>(current_Line.second.second) << "\n";
	}


	while (!trapped.empty())
	{
		current_Line = trapped.front();
		trapped.pop_front();
		toFile2 <<  current_Line.first << "\t";
		toFile2 <<  std::get<0>(current_Line.second.first) << "\t";
		toFile2 <<  std::get<1>(current_Line.second.first) << "\t";
		toFile2 <<  std::get<2>(current_Line.second.first) << "\t";
		toFile2 <<  std::get<0>(current_Line.second.second) << "\t";
		toFile2 <<  std::get<1>(current_Line.second.second) << "\t";
		toFile2 <<  std::get<2>(current_Line.second.second) << "\n";
	}

	  toFile1.close();
	  toFile2.close();

    return 0;
}
开发者ID:jqnorris,项目名称:InvasionPercolation,代码行数:70,代码来源:IP_3D.cpp

示例8: main

int main(int argc, char **argv)
{
	long int i, N;
	bool already_invaded;

	N = atoi(argv[1]);
	threshold = atof(argv[2]);
	srand48(atoi(argv[3]));

    Site start;
    start.loc = std::make_pair(0, 0);
    start.weight = 0;
    invadedSites.insert(start);
    for (int neigh=0;neigh<4; neigh++)
    {
    	Bond newBond;
    	double newStrength = drand48();
    	newBond = std::make_pair(newStrength, std::make_pair(start, get_neighbor(start, neigh)));
    	accessibleBonds.insert(std::make_pair(newStrength, newBond));
    }

    while(!accessibleBonds.empty())
    {
    	BondMap::iterator weakest;
    	weakest = accessibleBonds.begin();
    	accessibleBonds.erase(weakest);
    	invade_bond(weakest->second);
    	i++;
    	if(i == N)
    	{
    		accessibleBonds.clear();
    	}
    }

    std::stringstream fileName;
    fileName << "fractures" << argv[3] << ".txt";
	std::ofstream toFile1(fileName.str().c_str(), std::ios::trunc);
//	std::ofstream toFile2("trapped.txt", std::ios::trunc);
	toFile1 << growth.size() << "\n";
//	toFile2 << trapped.size() << "\n";
//	toFile1 << "Invasion for: temp" << "\n";
//	toFile2 << "Trapping for: temp" << "\n";
//	toFile1.precision(17);
//	toFile2.precision(17);
//
//	Bond current_Line;
//	while (!growth.empty())
//	{
//		current_Line = growth.front();
//		growth.pop_front();
//		toFile1 <<  current_Line.first << "\t";
//		toFile1 <<  current_Line.second.first.loc.first << "\t";
//		toFile1 <<  current_Line.second.first.loc.second << "\t";
//		toFile1 <<  current_Line.second.second.loc.first << "\t";
//		toFile1 <<  current_Line.second.second.loc.second << "\n";
//	}
//
//
//	while (!trapped.empty())
//	{
//		current_Line = trapped.front();
//		trapped.pop_front();
//		toFile2 <<  current_Line.first << "\t";
//		toFile2 <<  current_Line.second.first.loc.first << "\t";
//		toFile2 <<  current_Line.second.first.loc.second << "\t";
//		toFile2 <<  current_Line.second.second.loc.first << "\t";
//		toFile2 <<  current_Line.second.second.loc.second << "\n";
//	}
//
//	  toFile1.close();
//	  toFile2.close();

    return 0;
}
开发者ID:jqnorris,项目名称:InvasionPercolation,代码行数:74,代码来源:simulation.cpp


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