from os import listdir

def append_data_file_info():
	
	test_sets = ['furman_sahinidis', 'chen_grossmann_miller', 'grossmann_random', 'large_scale']
	
	for test_set in test_sets:
		dat_files_path='data/original_instances/' + test_set + '/dat_files/'
		#dat_files_path='data/mip_instances/' + test_set + '/'
		test_ids=listdir(dat_files_path) 
	
		for test_id in test_ids:
			if '~' not in test_id:
				
				file_name = 'data/original_instances/' + test_set + '/dat_files/' + test_id
				#file_name = 'data/mip_instances/' + test_set + '/' + test_id
				with open(file_name, 'r') as rf:
					lines = rf.readlines() 
				
				(original_info, public_info) = get_data_file_info(test_set)
				lines[0] = original_info
				lines[1] = public_info
				#print(lines)
				
				with open(file_name, 'w') as wf:
					wf.writelines(lines)
	



#f = open('min_matches_heuristics/data/original_instances/', 'r')
#print(f.read()) 

def get_data_file_info(test_set):
	
	if test_set == 'furman_sahinidis':
		original_info = 'Test case originally investigated by \"Furman, Sahinidis. Industrial and Engineering Chemistry Research 43(14), p. 3554-3565, 2004\".\n'
		public_info = 'Manually digitized and made publicly available by \"Letsios, Kouyialis, Misener. Computers and Chemical Engineering 113, p. 57-85, 2018\". \n'
	
	if test_set == 'chen_grossmann_miller':
		original_info = 'Test case originally investigated by \"Chen, Grossmann, Miller. Computers and Chemical Engineering 82, p. 68-83, 2015\". \n'
		public_info = 'Retrieved from www.minlp.org. \n'
	
	if test_set == 'grossmann_random':
		original_info = 'Test case originally investigated by \"Letsios, Kouyialis, Misener. Computers and Chemical Engineering 113, p. 57-85, 2018\". \n'
		public_info = 'Randomly generated by random procedure and seed provided as a personal communication from Ignacio Grossmann to Ruth Misener. \n'
	
	if test_set == 'large_scale':
		original_info = 'Test case originally investigated by \"Letsios, Kouyialis, Misener. Computers and Chemical Engineering 113, p. 57-85, 2018\". \n'
		public_info = 'Randomly generated by random procedure described in \"Letsios, Kouyialis, Misener. Computers and Chemical Engineering 113, p. 57-85, 2018\". \n'
	
	return (original_info, public_info)