-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallocator.py
More file actions
77 lines (67 loc) · 2.07 KB
/
allocator.py
File metadata and controls
77 lines (67 loc) · 2.07 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
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
76
from parser import *
from extractor import *
"""
tallying to production hours
[0, 1, 0, 1, 0, 0] -->2hours
[2, 0, 0, 1, 0, 0] -->3hours
"""
def Maximizing_production(Costs,units,machine_data,machinehours,expected_hours):
marker=1 #to find index of element to be adjusted
while(marker<len(machine_data)):
if(machine_data[marker]!=0):
break
marker+=1
else:
return machine_data
machinehours-=1
machine_data[marker]-=1
add=0
while(marker>-1):
marker-=1
add+=2
if(Costs[marker] is not None):
break
machine_data[marker]+=add
machinehours+=add
if(machinehours<expected_hours):
Maximizing_production(Costs,units,machine_data,machinehours,expected_hours)
return machine_data
"""
Calculating individual regional data(most minimum cost)
As cost is sorted proportionally, more the highest unit the cost is less
for i in range(6,0,-1):
machine.append(totalunit//units[i] )
totalunit/=units[i]
output << machines m1,m2,m3,m4,m5,m6
count= [1, 1, 1, 0, 1 ,0]
"""
def RegionalResult(capacity,expected_hours,regionName,Machines,Cost,units):
machine_data=Machines[:]
machinehours=0
totalcost=0
#Selecting the machines Based on minimal cost
k=len(units)-1
for i in range(len(units)-1,-1,-1):
if (capacity//units[i] is not 0 and Cost[i] is not None):
machine_data[k]=capacity//units[i]
machinehours+=(capacity//units[i])
capacity=capacity%units[i]
else:
machine_data[k]=0
k-=1
#if production faster than expected
if machinehours<expected_hours:
Maximizing_production(Costs,units,machine_data,machinehours,expected_hours)
return ParsingRegionalData(machine_data,Costs,Machines,regionName)
units=(10,20,40,80,160,320)
FileObj=AccessingDataset()
capacity=int(input("enter capacity"))
expected_hours=int(input("enter hours"))
Machines=Extract_MachineData(FileObj)
Output=''
for col in range(1,FileObj.ncols):
RegionName=FileObj.cell_value(0,col)
Costs=ExtractRegionalCost(FileObj,col)
#passing out individual cost to get base cost
Output+=str(RegionalResult(capacity,expected_hours,RegionName,Machines,Costs,units))+','
ParsingOutputData(Output)