-
Notifications
You must be signed in to change notification settings - Fork 0
/
csp_ai_1.1.py
75 lines (66 loc) · 2.79 KB
/
csp_ai_1.1.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
domain = ["wheat", "rice", "barley"]
variables = []
constraints = []
# dataset la vandhu key crop and value is a list containing the requirements for the crop to grow
# the list contains [minimum temp,max temp,min water level, min ph, max ph,[types of soil it can grow in]]
dataset = {
"rice": [35, 36, 14, 4, 6, ["clay", "alluvial"]],
"barley": [31, 37, 17, 8, 10, ["sandy", "saline"]],
"wheat": [37, 40, 20, 5, 7, ["alluvial", "black"]],
}
i = 0
def calculate_best_crop(soil_type, water, temperature, ph, i, variables):
c = 0
if i < 3:
crop = domain[i]
if soil_type in dataset[crop][5]:
c += 1
if water >= dataset[crop][2]:
c += 1
if ph >= dataset[crop][3] and ph <= dataset[crop][4]:
c += 1
if (
temperature >= dataset[crop][0]
and temperature <= dataset[crop][1]
):
c += 1
variables.append([c, crop])
# print(variables,"1")
calculate_best_crop(
soil_type, water, temperature, ph, i + 1, variables
)
return variables
else:
variables.append([c, crop])
# print(variables,'2')
calculate_best_crop(
soil_type, water, temperature, ph, i + 1, variables
)
return variables
else:
variables.append([c, crop])
# print(variables,'3')
calculate_best_crop(
soil_type, water, temperature, ph, i + 1, variables
)
return variables
else:
variables.append([c, crop])
# print(variables,'4')
calculate_best_crop(soil_type, water, temperature, ph, i + 1, variables)
return variables
else:
variables.append([c, crop])
calculate_best_crop(soil_type, water, temperature, ph, i + 1, variables)
return variables
else:
return variables
soil_type = input("enter the type of soil:")
water = int(input("enter the amount of water:"))
temperature = int(input("enter the surrounding temperature:"))
ph = int(input("enter the level of ph of the soil:"))
crop_rank = calculate_best_crop(soil_type, water, temperature, ph, i, variables)
crop_rank.sort(reverse=True)
print("The crops which are best suitable for growing in the land is in the order of:")
for i in crop_rank:
print(i[1])