def cal_estimation(case_config, input_file, results_file, utility_parameter): process = subprocess.call([ 'Rscript --vanilla {r_script_file} {input_file} ' '{number_of_alternatives} {case_config} {utility_parameter} {city_list} {results_file} ' '{alternative_2_variables} {alternative_3_variables} {alternative_4_variables} ' '{alternative_5_variables} {alternative_6_variables} {alternative_7_variables} {alternative_8_variables}' .format( r_script_file=RUNNER_MDCEV, input_file=input_file, number_of_alternatives=STATE_LISTS.__len__(), case_config=case_config, utility_parameter=convert_list_to_str(utility_parameter), city_list=convert_list_to_str(STATE_LISTS), results_file=results_file, alternative_2_variables=convert_list_to_str(utility_parameter), alternative_3_variables=convert_list_to_str(utility_parameter), alternative_4_variables=convert_list_to_str(utility_parameter), alternative_5_variables=convert_list_to_str(utility_parameter), alternative_6_variables=convert_list_to_str(utility_parameter), alternative_7_variables=convert_list_to_str(utility_parameter), alternative_8_variables=convert_list_to_str(utility_parameter), ) ], shell=True) return process
def cal_estimation(case_config, input_file, results_file, utility_parameter): process = subprocess.call([ 'Rscript --vanilla {r_script_file} {input_file} {number_of_alternatives} {case_config} {utility_parameter} {city_list} {results_file}' .format(r_script_file=RUNNER_MDCEV, input_file=input_file, number_of_alternatives=CITY_LISTS.__len__(), case_config=case_config, utility_parameter=utility_parameter, city_list=convert_list_to_str(CITY_LISTS), results_file=results_file) ], shell=True) return process
def estimation(self): for case_config in self.case_config_list: estimation_output_file = self._create_estimation_output_filename( case_config) print('This is the estimation file', estimation_output_file) process = subprocess.call([ 'Rscript --vanilla {r_script} {input_file} ' '{number_of_alternatives} {case_config} {utility_parameters} {state_list} {results_file} ' '{alternative_2_variables} {alternative_3_variables} {alternative_4_variables} ' '{alternative_5_variables} {alternative_6_variables} {alternative_7_variables} {alternative_8_variables}' .format( r_script=self.r_estimation, input_file=self.model_data_file, number_of_alternatives=self.alternative_list.__len__(), case_config=case_config, utility_parameters=convert_list_to_str( self.utility_variables), state_list=convert_list_to_str(self.alternative_list), results_file=estimation_output_file, alternative_2_variables=convert_list_to_str( self.alternatives_utility_variables[0]), alternative_3_variables=convert_list_to_str( self.alternatives_utility_variables[1]), alternative_4_variables=convert_list_to_str( self.alternatives_utility_variables[2]), alternative_5_variables=convert_list_to_str( self.alternatives_utility_variables[3]), alternative_6_variables=convert_list_to_str( self.alternatives_utility_variables[4]), alternative_7_variables=convert_list_to_str( self.alternatives_utility_variables[5]), alternative_8_variables=convert_list_to_str( self.alternatives_utility_variables[6]), ) ], shell=True) return
estimation_output_file = RESULTS_PATH + '/results' + '_{}'.format( case_config) + '_{}'.format('MDCEV_2') + '.txt' forecast_output_file = RESULTS_PATH + '/results' + '_{}'.format( case_config) + '_{}'.format('MDCEV_2') + '.txt' print estimation_output_file process = subprocess.call([ 'Rscript --vanilla {r_script_file} {input_file} ' '{number_of_alternatives} {case_config} {utility_parameters} {state_list} {results_file} ' '{alternative_2_variables} {alternative_3_variables} {alternative_4_variables} ' '{alternative_5_variables} {alternative_6_variables}'.format( r_script_file=RUNNER_MDCEV, input_file=input_file_path, number_of_alternatives=STATE_LISTS.__len__(), case_config=case_config, utility_parameters=convert_list_to_str(UTILITY_VARIABLES), state_list=convert_list_to_str(STATE_LISTS), results_file=estimation_output_file, alternative_2_variables=convert_list_to_str( UTILITY_VARIABLES_ALTERNATIVES[0]), alternative_3_variables=convert_list_to_str( UTILITY_VARIABLES_ALTERNATIVES[1]), alternative_4_variables=convert_list_to_str( UTILITY_VARIABLES_ALTERNATIVES[2]), alternative_5_variables=convert_list_to_str( UTILITY_VARIABLES_ALTERNATIVES[3]), alternative_6_variables=convert_list_to_str( UTILITY_VARIABLES_ALTERNATIVES[4]), ) ], shell=True)
variable_in_names = '' for i, item in enumerate(variable_combination): variable_in_names += str(item) if i != len(variable_combination) - 1: variable_in_names += '-' # write the file input_file_path = INPUT_DIR_PATH + '/input' + '_{}'.format( case_config) + '_{}'.format(variable_in_names) + '.csv' write_data_to_csv(input_file_path, results) output_file_path = RESULTS_PATH + '/results' + '_{}'.format( case_config) + '_{}'.format(variable_in_names) + '.txt' list_of_estimations.append( (case_config, input_file_path, output_file_path, convert_list_to_str(variable_combination))) # multiprocessing CAREFUL, DANGEROURS !!!!!! Monster !!!!! pool = Pool(processes=6) for item in list_of_estimations: print item pool.apply_async(cal_estimation, (item[0], item[1], item[2], item[3])) pool.close() pool.join() # # for case_config in case_config_list: # # To exclude the parameter # list_of_variables = case_config_excluding_variables(case_config) # # # generate the combination of the lists