Changeset 2414 for coopr.pysp/trunk/coopr/pysp/ef_writer_script.py
- Timestamp:
- Mar 8, 2010 10:18:14 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
coopr.pysp/trunk/coopr/pysp/ef_writer_script.py
r2248 r2414 24 24 25 25 # 26 # Setup command-line options26 # utility method to construct an option parser for ef writer arguments 27 27 # 28 28 29 parser = OptionParser() 30 parser.add_option("--model-directory", 31 help="The directory in which all model (reference and scenario) definitions are stored. Default is \".\".", 32 action="store", 33 dest="model_directory", 34 type="string", 35 default=".") 36 parser.add_option("--instance-directory", 37 help="The directory in which all instance (reference and scenario) definitions are stored. Default is \".\".", 38 action="store", 39 dest="instance_directory", 40 type="string", 41 default=".") 42 parser.add_option("--generate-weighted-cvar", 43 help="Add a weighted CVaR term to the primary objective", 44 action="store_true", 45 dest="generate_weighted_cvar", 46 default=False) 47 parser.add_option("--cvar-weight", 48 help="The weight associated with the CVaR term in the risk-weighted objective formulation.", 49 action="store", 50 dest="cvar_weight", 51 type="float", 52 default=1.0) 53 parser.add_option("--risk-alpha", 54 help="The probability threshold associated with cvar (or any future) risk-oriented performance metrics.", 55 action="store", 56 dest="risk_alpha", 57 type="float", 58 default=0.95) 59 parser.add_option("--output-file", 60 help="Specify the name of the extensive form output file", 61 action="store", 62 dest="output_file", 63 type="string", 64 default="efout.lp") 65 parser.add_option("--profile", 66 help="Enable profiling of Python code. The value of this option is the number of functions that are summarized.", 67 action="store", 68 dest="profile", 69 default=0) 70 parser.usage="efwriter [options]" 29 def construct_ef_writer_options_parser(usage_string): 71 30 31 parser = OptionParser() 32 parser.add_option("--verbose", 33 help="Generate verbose output, beyond the usual status output. Default is False.", 34 action="store_true", 35 dest="verbose", 36 default=False) 37 parser.add_option("--model-directory", 38 help="The directory in which all model (reference and scenario) definitions are stored. Default is \".\".", 39 action="store", 40 dest="model_directory", 41 type="string", 42 default=".") 43 parser.add_option("--instance-directory", 44 help="The directory in which all instance (reference and scenario) definitions are stored. Default is \".\".", 45 action="store", 46 dest="instance_directory", 47 type="string", 48 default=".") 49 parser.add_option("--generate-weighted-cvar", 50 help="Add a weighted CVaR term to the primary objective", 51 action="store_true", 52 dest="generate_weighted_cvar", 53 default=False) 54 parser.add_option("--cvar-weight", 55 help="The weight associated with the CVaR term in the risk-weighted objective formulation.", 56 action="store", 57 dest="cvar_weight", 58 type="float", 59 default=1.0) 60 parser.add_option("--risk-alpha", 61 help="The probability threshold associated with cvar (or any future) risk-oriented performance metrics.", 62 action="store", 63 dest="risk_alpha", 64 type="float", 65 default=0.95) 66 parser.add_option("--output-file", 67 help="Specify the name of the extensive form output file", 68 action="store", 69 dest="output_file", 70 type="string", 71 default="efout.lp") 72 parser.add_option("--profile", 73 help="Enable profiling of Python code. The value of this option is the number of functions that are summarized.", 74 action="store", 75 dest="profile", 76 default=0) 77 parser.add_option("--disable-gc", 78 help="Disable the python garbage collecter. Default is False.", 79 action="store_true", 80 dest="disable_gc", 81 default=False) 82 parser.usage=usage_string 83 84 return parser 85 72 86 def run_ef_writer(options, args): 73 87 … … 84 98 risk_alpha = options.risk_alpha 85 99 86 write_ef_from_scratch(os.path.expanduser(options.model_directory), os.path.expanduser(options.instance_directory), os.path.expanduser(options.output_file), \ 100 write_ef_from_scratch(os.path.expanduser(options.model_directory), 101 os.path.expanduser(options.instance_directory), 102 os.path.expanduser(options.output_file), 103 options.verbose, 87 104 generate_weighted_cvar, cvar_weight, risk_alpha) 88 89 return90 105 91 106 def run(args=None): … … 96 111 # 97 112 98 # for a one-pass execution, garbage collection doesn't make99 # much sense - so I'm disabling it. Because: It drops the run-time100 # by a factor of 3-4 on bigger instances.101 gc.disable()102 103 113 # 104 114 # Parse command-line options. 105 115 # 106 116 try: 107 (options, args) = parser.parse_args(args=args) 117 options_parser = construct_ef_writer_options_parser("efwriter [options]") 118 (options, args) = options_parser.parse_args(args=args) 108 119 except SystemExit: 109 120 # the parser throws a system exit if "-h" is specified - catch 110 121 # it to exit gracefully. 111 122 return 123 124 if options.disable_gc is True: 125 gc.disable() 126 else: 127 gc.enable() 112 128 113 129 if options.profile > 0: … … 140 156 141 157 gc.enable() 158 142 159 return ans 143 160
Note: See TracChangeset
for help on using the changeset viewer.