-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_prompt.py
More file actions
38 lines (36 loc) · 1.92 KB
/
problem_prompt.py
File metadata and controls
38 lines (36 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def generate_prompt_for_dict(problem_dict):
prompt = ''
prompt += 'Given an ' + str(problem_dict['dim']) + ' dimensional optimization problem with ' + problem_dict['obj_language'] + ' formulation:\n\n'
if problem_dict['obj_language'] == 'Latex' or problem_dict['obj_language'] == 'latex':
formula_latex = 'Minimize: '
formula_latex += problem_dict['formula']
if problem_dict['constraints'] != 'None':
constraint = problem_dict["constraints"]
constraint_formula = "\n" + r'\\\text{Subject to: }\\'
if 'g' in constraint.keys():
num_of_g_constraints = len(constraint['g'])
for i in range(num_of_g_constraints):
constraint_formula += r'g_' + str(i) + r'(x) = '
constraint_formula += constraint['g'][i]
constraint_formula += r'\leq 0\\'
if 'h' in constraint.keys():
num_of_h_constraints = len(constraint['h'])
for i in range(num_of_h_constraints):
constraint_formula += r'h_' + str(i) + r'(x) = '
constraint_formula += constraint['h'][i]
constraint_formula += r'= 0\\'
formula_latex += constraint_formula
prompt += formula_latex
else:
prompt += problem_dict['formula']
# search_range = [-problem['search_range'], problem['search_range']]
prompt += '\n\nGenerate a solver for it.\n'
prompt += f'Note that the feasible domain is:{problem_dict["search_range"]}.\n\n'
prompt += f'The problem should be solved within {problem_dict["FEs"]} function evaluations.\n'
if problem_dict['obj_language'] == 'Latex' or problem_dict['obj_language'] == 'latex':
pass
else:
if problem_dict['constraints'] != 'None':
prompt += 'The constraints for solutions:\n'
prompt += f'{problem_dict["constraints"]}'
return prompt