⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 argpack.cc

📁 TGFF省城程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
// Copyright 2000 by Keith Vallerio, David Rhodes, and Robert Dick.// All rights reserved.#include <cmath>#include <functional>#include <iomanip>#include <map>#include "RMath.h"#include "RPair.h"#include "RVector.h"#include "RecVector.h"#include "ArgPack.h"#include "RStd.h"#include "PGraph.h"#include "TGraph.h"#include "RGen.h"#include "DBase.h"using namespace std;using namespace rstd;/*###########################################################################*/// PrivateArgPack * ArgPack::def_ap_ = 0;/*===========================================================================*/// Public/*===========================================================================*/ArgPack::ArgPack(int argc, char * const argv[]) :	tg_label("TASK_GRAPH"),	tg_cnt(3),	vertex_time(100),	deadline_jitter(0.0),	vertex_cnt_av(20),	vertex_cnt_mul(5),	vertex_in_deg(5),	vertex_out_deg(5),	task_unique(false),	task_type_cnt(static_cast<int>((tg_cnt * vertex_cnt_av) / 3)),	trans_unique(false),	trans_type_cnt(static_cast<int>((tg_cnt * vertex_cnt_av *		(vertex_in_deg + vertex_out_deg)) / 12)),	task_attrib_name(),	task_attrib_av(),	task_attrib_mul(),	task_attrib_round(),	prob_multi_start_nodes(0.0),	start_node_av(2),	start_node_mul(1),	p_laxity(1.0),	p_greater_deadline(false),	prob_hard_deadline(1.0),	soft_deadline_mul(1.0),	table_label("PE"),	table_cnt(5),	type_table_ratio(0.5),	period_mul(3),	entries_per_type_av(1.0),	entries_per_type_mul(0.0),	table_name(1),	table_av(1),	table_mul(1),	table_jitter(1),	table_round(1),	type_name(1),	type_av(1),	type_mul(1),	type_jitter(1),	type_round(1),	gen_series_parallel(false),   series_subgraph_fork_out(0),	series_must_rejoin(false),	series_len_av(5),	series_len_mul(1),	series_wid_av(2),	series_wid_mul(1),	series_local_xover (0),	series_global_xover (0),	seed(0),	misc_type_cnt(0),	prob_periodic(1.0),	aperiodic_min_used (false),	aperiodic_min_av(10),	aperiodic_min_mul(5),	data_file_name("tgff.tgff"),	eps_file_name("tgff.eps"),	vcg_file_name("tgff.vcg"),	opt_file_name("tgff.tgffopt"),	data_out_(),	eps_out_(),	vcg_out_(),	opt_in_(){	RASSERT(! def_ap_);	def_ap_ = this;	period_mul[0] = 0.5;	period_mul[1] = 1.0;	period_mul[2] = 2.0;	table_name[0] = "price";	table_av[0] = 10.0;	table_mul[0] = 5.0;	table_jitter[0] = 0.5;	table_round[0] = 0.0;	type_name[0] = "exec_time";	type_av[0] = 100.0;	type_mul[0] = 40.0;	type_jitter[0] = 0.5;	type_round[0] = 0.0;	if (argc != 2) {		cout << help_;		exit(EXIT_FAILURE);	}	data_file_name = string(argv[1]) + ".tgff";	eps_file_name = string(argv[1]) + ".eps";	vcg_file_name = string(argv[1]) + ".vcg";	opt_file_name = string(argv[1]) + ".tgffopt";	opt_in_.open(opt_file_name.c_str());	if (! opt_in_) {		cout << "Unable to open input file.\n";		exit(EXIT_FAILURE);	}	eps_out_.open(eps_file_name.c_str());	if (! eps_out_) {		cout << "Unable to open EPS output file.\n";		exit(EXIT_FAILURE);	}	vcg_out_.open(vcg_file_name.c_str());	if (! vcg_out_) {		cout << "Unable to open VCG output file.\n";		exit(EXIT_FAILURE);	} else {		vcg_out_ << "graph: { label: \"" << vcg_file_name << "\"\n";		vcg_out_ << "display_edge_labels: yes\n";	}	double h_period = parse();	ofstream real_out(data_file_name.c_str());	if (! real_out) {		cout << "Unable to open TGFF output files.\n";		exit(EXIT_FAILURE);	}	if (h_period > 0.0) {		real_out << "@HYPERPERIOD " << h_period << "\n\n";	}	data_out_ << endl;// Copy the output buffer to the real output file.	real_out << data_out_.str();	vcg_out_ << "\n } \n";}/*===========================================================================*/ArgPack::~ArgPack() {	RASSERT(def_ap_);	def_ap_ = 0;}/*===========================================================================*/// Private/*===========================================================================*/doubleArgPack::parse() {	RVector<double> h_period;	int line = 0;	map<string, int> tg_offset;	map<string, int> table_offset;	tg_offset.insert(make_pair(tg_label, 0));	table_offset.insert(make_pair(table_label, 0));	while (1) {		string s;		bool wrap = true;// Get a single command		do {			string line_buf;			if (! getline(opt_in_, line_buf)) {				if (h_period.size()) {					return lcm(h_period);				} else {					return -1.0;				}			}			line++;			RVector<string> tokenized = tokenize(line_buf);						if (! tokenized.empty() &&				tokenized[0][0] != '#')			{				s += line_buf;				if (! s.empty() && s[s.size() - 1] == '\\')					s.erase(s.size() - 1);				else					wrap = false;			}		} while (wrap);		string first = first_token(s);		if (first.empty())			parse_error(line);		const string command = first;		pop_token(s);		RVector<string> vec = tokenize(s);		RVector<string> top_rvec(0);		if (! vec.empty())			top_rvec = tokenize(s, ",");		MVector<2, string> rvec(top_rvec.size());		MAP(x, rvec.size()) {			rvec[x] = tokenize(top_rvec[x]);		}/*-------------------------------------*/		if (command == "tg_label") {			if (vec.size() != 1) parse_error(line);			tg_label = vec[0];			tg_offset.insert(make_pair(tg_label, 0));		} else if (command == "tg_offset") {			if (vec.size() != 2) parse_error(line);			const string & tg_name = vec[0];			const long offset = Conv(vec[1]);			tg_offset[tg_name] = offset;		} else if (command == "tg_cnt") {			if (vec.size() != 1 ||			  (tg_cnt = Conv(vec[0])) < 0)				parse_error(line);		} else if (command == "task_trans_time") {			if (vec.size() != 1 ||			  (vertex_time = Conv(vec[0])) < 0)				parse_error(line);		} else if (command == "deadline_jitter") {			if (vec.size() != 1) parse_error(line);			deadline_jitter = Conv(vec[0]);			if (deadline_jitter < 0.0 || deadline_jitter >= 1.0) {				parse_error(line);			}		} else if (command == "pack_schedule") {			if ( !(vec.size() == 10 || vec.size() == 11) )				parse_error(line);			int		num_task_graphs	 = Conv(vec[0]);			int		avg_tasks_per_pe = Conv(vec[1]);			if( num_task_graphs < 1 || avg_tasks_per_pe < 1)				parse_error(line);			double	avg_task_time	= Conv(vec[2]);			double	mul_task_time	= Conv(vec[3]);			double	task_slack		= Conv(vec[4]);			double	task_round		= Conv(vec[5]);			int		num_pe_types	= Conv(vec[6]);			int		num_pe_soln		= Conv(vec[7]);			if( avg_task_time <= 0.0 ||				avg_task_time+abs(mul_task_time) <= 0.0 ||				task_slack < 0.0 ||				num_pe_types < 1 ||				num_pe_soln < 1 )				parse_error(line);			int		num_com_types	= Conv(vec[8]);			int		num_com_soln	= Conv(vec[9]);			if( num_com_types < 1 ||				num_com_soln < 1 )				parse_error(line);			double	arc_fill_factor	= 1.0;			if( vec.size() == 11 )				arc_fill_factor	= Conv(vec[10]);			// here goes...			PGraph pg(	eps_out_,						num_task_graphs,						avg_tasks_per_pe,						avg_task_time,	/* PE STUFF */						mul_task_time,						task_slack,						task_round,						num_pe_types,						num_pe_soln,						num_com_types,	/* COM STUFF */						num_com_soln,						arc_fill_factor);			pg.print_to(data_out_);			return pg.h_period();		} else if (command == "task_cnt") {			if (vec.size() != 2) parse_error(line);			vertex_cnt_av = Conv(vec[0]);			vertex_cnt_mul = Conv(vec[1]);			if (vertex_cnt_av - abs(vertex_cnt_mul) < 0) {				parse_error(line);			}		} else if (command == "task_degree") {			if (vec.size() != 2) parse_error(line);			vertex_in_deg = Conv(vec[0]);			vertex_out_deg = Conv(vec[1]);			/* when using "pack_schedule" -1 indicates "no limit"			if (vertex_in_deg_ < 1 || vertex_out_deg_ < 1)				parse_error(line);			*/		} else if (command == "task_unique") {			if (vec.size() > 1) parse_error(line);			if (vec.size())				task_unique = Conv(vec[0]);			else				task_unique = true;		} else if (command == "prob_multi_start_nodes") {			if (vec.size() != 1) parse_error(line);			prob_multi_start_nodes = Conv(vec[0]);		} else if (command == "start_node") {			if (vec.size() != 2) parse_error(line);			start_node_av = Conv(vec[0]);			start_node_mul = Conv(vec[1]);			if (start_node_av < 1) parse_error(line);		} else if (command == "task_type_cnt") {			if (vec.size() != 1 ||			  (task_type_cnt = Conv(vec[0])) < 0)				parse_error(line);		} else if (command == "trans_unique") {			if (vec.size() > 1) parse_error(line);			if (vec.size() == 1)				trans_unique = Conv(vec[0]);			else				trans_unique = true;		} else if (command == "trans_type_cnt") {			if (vec.size() != 1 ||			  (trans_type_cnt = Conv(vec[0])) < 0)				parse_error(line);		} else if (command == "task_attrib") {			task_attrib_name.clear();			task_attrib_av.clear();			task_attrib_mul.clear();			task_attrib_round.clear();			MAP(x, rvec.size()) {				if (rvec[x].size() < 3 || rvec[x].size() > 4)					parse_error(line);				task_attrib_name.push_back(rvec[x][0]);				task_attrib_av.push_back(Conv(rvec[x][1]));				task_attrib_mul.push_back(Conv(rvec[x][2]));					if (rvec[x].size() >= 4) {					task_attrib_round.push_back(Conv(rvec[x][3]));				} else {					task_attrib_round.push_back(0.0);				}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -