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


C++ Arc::Set方法代码示例

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


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

示例1: ReadTrans

// Read and create transportation network
void ReadTrans(vector<Node>& Nodes, vector<Arc>& Arcs, const char* fileinput) {
	// Create default nodes and arcs
	vector<string> DefNodes(0), DefFrom(0), DefTo(0), DefInf(0);
	Node TempNode;
	Arc TempArc;
	int NInfra = TransInfra.size(), NFleet = 0, NComm = TransComm.size(), k = 0;
	string Infra = "", Fleet = "", FleetInf = "", Comm = "", Coal = "";
	
	// Determine the number of fleet
	for (unsigned int i = 0; i < NInfra; ++i)
		NFleet += TransInfra[i].size()-1;
	
	vector< vector<bool> > NodeTable(0), ArcTable(0);
	vector<bool> TableColumn(NFleet, false);
	
	// For each line in the definition of infrastructures
	for (unsigned int i = 0; i < NInfra; ++i) {
		Infra.push_back(TransInfra[i][0]);
		
		// Create an arc (for infrastructure capacity constraints)
		DefFrom.push_back(TransInfra[i].substr(0,1) + TransInfra[i].substr(0,1));
		DefTo.push_back("XX");
		DefInf.push_back("");
		ArcTable.push_back(TableColumn);
		
		// For each fleet within that infrastructure
		for (unsigned int j = 1; j < TransInfra[i].size(); ++j) {
			// Create an arc (for fleet capacity constraints)
			DefFrom.push_back(TransInfra[i].substr(j,1) + TransInfra[i].substr(j,1));
			DefTo.push_back("XX");
			DefInf.push_back("");
			ArcTable.push_back(TableColumn);
			
			Fleet.push_back(TransInfra[i][j]);
			FleetInf.push_back(TransInfra[i][0]);
			
			ArcTable[ArcTable.size()-1][k] = true;
			ArcTable[ArcTable.size()-j-1][k] = true;
			k++;
		}
	}
	
	// For each commodity
	for (unsigned int i = 0; i < NComm; ++i) {
		Comm.push_back(TransComm[i][0]);
		DefNodes.push_back(TransComm[i].substr(0,1) + "T");
		NodeTable.push_back(TableColumn);
		
		for (unsigned int j = 1; j < TransComm[i].size(); ++j) {
			// Find for each fleet that the commodity can use
			k = Fleet.find(TransComm[i][j]);
			if (k >= 0) {
				// Create arc
				DefFrom.push_back(Fleet.substr(k,1) + Fleet.substr(k,1));
				DefTo.push_back(TransComm[i].substr(0,1) + "T");
				DefInf.push_back(FleetInf.substr(k,1) + FleetInf.substr(k,1));
				ArcTable.push_back(TableColumn);
				
				ArcTable[ArcTable.size()-1][k] = true;
				NodeTable[NodeTable.size()-1][k] = true;
			}
		}
	}
	
	char* t_read;
	char line[CHAR_LINE];
	int i = 0;
	
	TempNode.Set("Step", TransStep);
	TempArc.Set("FromStep", TransStep);
	TempArc.Set("ToStep", TransStep);
	
	FILE *file = fopen(fileinput, "r");
	if (file != NULL) {
		for (;;) {
			// Read a line from the file and finish if empty is read
			if (fgets(line, sizeof line, file) == NULL)
				break;
			
			// Remove comments and end of line characters
			CleanLine(line);
			
			// Skip first line, then read the rest
			if (i!=0) {
				string from, to, fleetlist, swap;
				vector<bool> ShowNode(NodeTable.size(), false), ShowArc(ArcTable.size(), false);
				int kk, swapindex;
				
				// Read from and to codes
				t_read = strtok(line,",");
				from = string(t_read);
				t_read = strtok(NULL,",");
				to = string(t_read);
				
				// Distance
				t_read = strtok(NULL,",");
				TempArc.Set("Distance", string(t_read));
				
				// Read allowed fleet and determine what nodes and arcs will be appropriate
//.........这里部分代码省略.........
开发者ID:christos-tsotskas,项目名称:NETPLAN,代码行数:101,代码来源:read.cpp


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