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

📄 parse.c

📁 蚁群算法的程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/* This file has been generated with opag 0.6.4.  */#include <stdio.h>#include <string.h>#include <assert.h>#include <limits.h>#include <stdlib.h>#include "InOut.h"#include "utilities.h"#include "ants.h"#include "ls.h"#ifndef STR_ERR_UNKNOWN_LONG_OPT# define STR_ERR_UNKNOWN_LONG_OPT   "%s: unrecognized option `--%s'\n"#endif#ifndef STR_ERR_LONG_OPT_AMBIGUOUS# define STR_ERR_LONG_OPT_AMBIGUOUS "%s: option `--%s' is ambiguous\n"#endif#ifndef STR_ERR_MISSING_ARG_LONG# define STR_ERR_MISSING_ARG_LONG   "%s: option `--%s' requires an argument\n"#endif#ifndef STR_ERR_UNEXPEC_ARG_LONG# define STR_ERR_UNEXPEC_ARG_LONG   "%s: option `--%s' doesn't allow an argument\n"#endif#ifndef STR_ERR_UNKNOWN_SHORT_OPT# define STR_ERR_UNKNOWN_SHORT_OPT  "%s: unrecognized option `-%c'\n"#endif#ifndef STR_ERR_MISSING_ARG_SHORT# define STR_ERR_MISSING_ARG_SHORT  "%s: option `-%c' requires an argument\n"#endif#define STR_HELP_TRIES \"  -r, --tries          # number of independent trials\n"#define STR_HELP_TOURS \"  -s, --tours          # number of steps in each trial\n"#define STR_HELP_TIME \"  -t, --time           # maximum time for each trial\n"#define STR_HELP_TSPLIBFILE \"  -i, --tsplibfile     f inputfile (TSPLIB format necessary)\n"#define STR_HELP_OPTIMUM \"  -o, --optimum        # stop if tour better or equal optimum is found\n"#define STR_HELP_ANTS \"  -m, --ants           # number of ants\n"#define STR_HELP_NNANTS \"  -g, --nnants         # nearest neighbours in tour construction\n"#define STR_HELP_ALPHA \"  -a, --alpha          # alpha (influence of pheromone trails)\n"#define STR_HELP_BETA \"  -b, --beta           # beta (influence of heuristic information)\n"#define STR_HELP_RHO \"  -e, --rho            # rho: pheromone trail evaporation\n"#define STR_HELP_Q0 \"  -q, --q0             # q_0: prob. of best choice in tour construction\n"#define STR_HELP_ELITISTANTS \"  -c, --elitistants    # number of elitist ants\n"#define STR_HELP_RASRANKS \"  -f, --rasranks       # number of ranks in rank-based Ant System\n"#define STR_HELP_NNLS \"  -k, --nnls           # No. of nearest neighbors for local search\n"#define STR_HELP_LOCALSEARCH \"  -l, --localsearch    0: no local search   1: 2-opt   2: 2.5-opt   3: 3-opt\n"#define STR_HELP_DLB \"  -d, --dlb            1 use don't look bits in local search\n"#define STR_HELP_AS \"  -u, --as              apply basic Ant System\n"#define STR_HELP_EAS \"  -v, --eas             apply elitist Ant System\n"#define STR_HELP_RAS \"  -w, --ras             apply rank-based version of Ant System\n"#define STR_HELP_MMAS \"  -x, --mmas            apply MAX-MIN ant system\n"#define STR_HELP_BWAS \"  -y, --bwas            apply best-worst ant system\n"#define STR_HELP_ACS \"  -z, --acs             apply ant colony system\n"#define STR_HELP_HELP \"  -h, --help            display this help text and exit\n"#define STR_HELP \	STR_HELP_TRIES \	STR_HELP_TOURS \	STR_HELP_TIME \	STR_HELP_TSPLIBFILE \	STR_HELP_OPTIMUM \	STR_HELP_ANTS \	STR_HELP_NNANTS \	STR_HELP_ALPHA \	STR_HELP_BETA \	STR_HELP_RHO \	STR_HELP_Q0 \	STR_HELP_ELITISTANTS \	STR_HELP_RASRANKS \	STR_HELP_NNLS \	STR_HELP_LOCALSEARCH \	STR_HELP_DLB \	STR_HELP_AS \	STR_HELP_EAS \	STR_HELP_RAS \	STR_HELP_MMAS \	STR_HELP_BWAS \	STR_HELP_ACS \STR_HELP_HELPstruct options {		/* Set to 1 if option --tries (-r) has been specified.  */	unsigned int opt_tries : 1;		/* Set to 1 if option --tours (-s) has been specified.  */	unsigned int opt_tours : 1;		/* Set to 1 if option --time (-t) has been specified.  */	unsigned int opt_time : 1;		/* Set to 1 if option --tsplibfile (-i) has been specified.  */	unsigned int opt_tsplibfile : 1;		/* Set to 1 if option --optimum (-o) has been specified.  */	unsigned int opt_optimum : 1;		/* Set to 1 if option --ants (-m) has been specified.  */	unsigned int opt_ants : 1;		/* Set to 1 if option --nnants (-g) has been specified.  */	unsigned int opt_nnants : 1;		/* Set to 1 if option --alpha (-a) has been specified.  */	unsigned int opt_alpha : 1;		/* Set to 1 if option --beta (-b) has been specified.  */	unsigned int opt_beta : 1;		/* Set to 1 if option --rho (-e) has been specified.  */	unsigned int opt_rho : 1;		/* Set to 1 if option --q0 (-q) has been specified.  */	unsigned int opt_q0 : 1;		/* Set to 1 if option --elitistants (-c) has been specified.  */	unsigned int opt_elitistants : 1;		/* Set to 1 if option --rasranks (-f) has been specified.  */	unsigned int opt_rasranks : 1;		/* Set to 1 if option --nnls (-k) has been specified.  */	unsigned int opt_nnls : 1;		/* Set to 1 if option --localsearch (-l) has been specified.  */	unsigned int opt_localsearch : 1;		/* Set to 1 if option --dlb (-d) has been specified.  */	unsigned int opt_dlb : 1;		/* Set to 1 if option --as (-u) has been specified.  */	unsigned int opt_as : 1;		/* Set to 1 if option --eas (-v) has been specified.  */	unsigned int opt_eas : 1;		/* Set to 1 if option --ras (-w) has been specified.  */	unsigned int opt_ras : 1;		/* Set to 1 if option --mmas (-x) has been specified.  */	unsigned int opt_mmas : 1;		/* Set to 1 if option --bwas (-y) has been specified.  */	unsigned int opt_bwas : 1;		/* Set to 1 if option --acs (-z) has been specified.  */	unsigned int opt_acs : 1;		/* Set to 1 if option --help (-h) has been specified.  */	unsigned int opt_help : 1;		/* Argument to option --tries (-r).  */	const char *arg_tries;		/* Argument to option --tours (-s).  */	const char *arg_tours;		/* Argument to option --time (-t).  */	const char *arg_time;		/* Argument to option --tsplibfile (-i).  */	const char *arg_tsplibfile;		/* Argument to option --optimum (-o).  */	const char *arg_optimum;		/* Argument to option --ants (-m).  */	const char *arg_ants;		/* Argument to option --nnants (-g).  */	const char *arg_nnants;		/* Argument to option --alpha (-a).  */	const char *arg_alpha;		/* Argument to option --beta (-b).  */	const char *arg_beta;		/* Argument to option --rho (-e).  */	const char *arg_rho;		/* Argument to option --q0 (-q).  */	const char *arg_q0;		/* Argument to option --elitistants (-c).  */	const char *arg_elitistants;		/* Argument to option --rasranks (-f).  */	const char *arg_rasranks;		/* Argument to option --nnls (-k).  */	const char *arg_nnls;		/* Argument to option --localsearch (-l).  */	const char *arg_localsearch;		/* Argument to option --dlb (-d).  */	const char *arg_dlb;	};/* Parse command line options.  Return index of first non-option argument,or -1 if an error is encountered.  */int parse_options (struct options *const options, const char *const program_name, const int argc, char **const argv){	static const char *const optstr__tries = "tries";	static const char *const optstr__tours = "tours";	static const char *const optstr__time = "time";	static const char *const optstr__tsplibfile = "tsplibfile";	static const char *const optstr__optimum = "optimum";	static const char *const optstr__ants = "ants";	static const char *const optstr__nnants = "nnants";	static const char *const optstr__alpha = "alpha";	static const char *const optstr__beta = "beta";	static const char *const optstr__rho = "rho";	static const char *const optstr__q0 = "q0";	static const char *const optstr__elitistants = "elitistants";	static const char *const optstr__rasranks = "rasranks";	static const char *const optstr__nnls = "nnls";	static const char *const optstr__localsearch = "localsearch";	static const char *const optstr__dlb = "dlb";	static const char *const optstr__as = "as";	static const char *const optstr__eas = "eas";	static const char *const optstr__ras = "ras";	static const char *const optstr__mmas = "mmas";	static const char *const optstr__bwas = "bwas";	static const char *const optstr__acs = "acs";	static const char *const optstr__help = "help";	int i = 0;	options->opt_tries = 0;	options->opt_tours = 0;	options->opt_time = 0;	options->opt_tsplibfile = 0;	options->opt_optimum = 0;	options->opt_ants = 0;	options->opt_nnants = 0;	options->opt_alpha = 0;	options->opt_beta = 0;	options->opt_rho = 0;	options->opt_q0 = 0;	options->opt_elitistants = 0;	options->opt_rasranks = 0;	options->opt_nnls = 0;	options->opt_localsearch = 0;	options->opt_dlb = 0;	options->opt_as = 0;	options->opt_eas = 0;	options->opt_ras = 0;	options->opt_mmas = 0;	options->opt_bwas = 0;	options->opt_acs = 0;	options->opt_help = 0;	options->arg_tries = 0;	options->arg_tours = 0;	options->arg_time = 0;	options->arg_tsplibfile = 0;	options->arg_optimum = 0;	options->arg_ants = 0;	options->arg_nnants = 0;	options->arg_alpha = 0;	options->arg_beta = 0;	options->arg_rho = 0;	options->arg_q0 = 0;	options->arg_elitistants = 0;	options->arg_rasranks = 0;	options->arg_nnls = 0;	options->arg_localsearch = 0;	options->arg_dlb = 0;	while (++i < argc)	{		const char *option = argv [i];		if (*option != '-')			return i;		else if (*++option == '\0')			return i;		else if (*option == '-')		{			const char *argument;			size_t option_len;			++option;			if ((argument = strchr (option, '=')) == option)				goto error_unknown_long_opt;			else if (argument == 0)				option_len = strlen (option);			else				option_len = argument++ - option;			switch (*option)			{			case '\0':				return i + 1;			case 'a':				if (strncmp (option + 1, optstr__acs + 1, option_len - 1) == 0)				{					if (option_len <= 1)						goto error_long_opt_ambiguous;					if (argument != 0)					{						option = optstr__acs;						goto error_unexpec_arg_long;					}					options->opt_acs = 1;					break;				}				else if (strncmp (option + 1, optstr__alpha + 1, option_len - 1) == 0)				{					if (option_len <= 1)						goto error_long_opt_ambiguous;					if (argument != 0)						options->arg_alpha = argument;					else if (++i < argc)						options->arg_alpha = argv [i];					else					{						option = optstr__alpha;						goto error_missing_arg_long;					}					options->opt_alpha = 1;					break;				}				else if (strncmp (option + 1, optstr__ants + 1, option_len - 1) == 0)				{					if (option_len <= 1)						goto error_long_opt_ambiguous;					if (argument != 0)						options->arg_ants = argument;					else if (++i < argc)						options->arg_ants = argv [i];					else					{						option = optstr__ants;						goto error_missing_arg_long;					}					options->opt_ants = 1;					break;				}				else if (strncmp (option + 1, optstr__as + 1, option_len - 1) == 0)				{					if (option_len <= 1)						goto error_long_opt_ambiguous;					if (argument != 0)					{						option = optstr__as;						goto error_unexpec_arg_long;					}					options->opt_as = 1;					break;				}				goto error_unknown_long_opt;			case 'b':				if (strncmp (option + 1, optstr__beta + 1, option_len - 1) == 0)				{					if (option_len <= 1)						goto error_long_opt_ambiguous;					if (argument != 0)						options->arg_beta = argument;					else if (++i < argc)						options->arg_beta = argv [i];					else					{						option = optstr__beta;

⌨️ 快捷键说明

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