-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBin.java
More file actions
152 lines (121 loc) · 3.93 KB
/
Bin.java
File metadata and controls
152 lines (121 loc) · 3.93 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import javax.crypto.Mac;
import java.util.*;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
public class Bin
{
public int binID;
public float height;
public float width;
public boolean isItOpened=false;
public float widthLeft;
public float heightLeft;
public float totalCapacityLeft;
public Bin(int binID, float width, float height)
{
this.binID=binID;
this.width=width;
this.height=height;
this.isItOpened=false;
this.widthLeft=width;
this.heightLeft=height;
this.totalCapacityLeft=width*height;
}
public Bin(Bin m)
{
this.binID = m.binID;
this.width = m.width;
this.height = m.height;
this.isItOpened = m.isItOpened;
this.heightLeft = m.heightLeft;
this.widthLeft = m.widthLeft;
this.totalCapacityLeft=m.totalCapacityLeft;
}
public static ArrayList<Bin> CopyBins(ArrayList<Bin> bins)
{
ArrayList<Bin> ret=new ArrayList<>();
for(int i=0;i <bins.size(); i++)
{
Bin m=new Bin(bins.get(i));
ret.add(m);
}
return ret;
}
public static int ContainsBin(ArrayList<Bin> bins, Bin bin)
{
int index=-1;
for(int i=0; i<bins.size();i++)
{
if(bins.get(i).binID==bin.binID)
{
index=i;
break;
}
}
return index;
}
public float getheightLeft() { return heightLeft; }
public float getwidthLeft() { return widthLeft; }
public float getTotalCapacityLeft(){return totalCapacityLeft; }
public static Bin UpdateBin(Bin m, Item t)
{
Bin mUpdated=new Bin(m);
mUpdated.heightLeft=mUpdated.heightLeft-t.heightRequest;
mUpdated.widthLeft=mUpdated.widthLeft-t.widthRequest;
mUpdated.totalCapacityLeft=mUpdated.totalCapacityLeft-t.widthRequest*t.heightRequest;
mUpdated.isItOpened=true;
return mUpdated;
}
public static ArrayList<Bin> BinSorter(ArrayList<Bin> bins, String type, String typeOfOrder)
{
ArrayList<Bin> ret = new ArrayList<>();
for(int i=0; i<bins.size(); i++)
{
Bin m=new Bin(bins.get(i));
ret.add(m);
}
if(type.equals("All"))
{
Collections.sort(ret, new Comparator<Bin>() {
@Override
public int compare(Bin p1, Bin p2) {
return (int) (p1.totalCapacityLeft - p2.totalCapacityLeft); // Ascending
}
});
ret.sort(Comparator.comparingDouble(Bin::getTotalCapacityLeft)); //smallest to largest
}
else if(type.equals("Width"))
{
Collections.sort(ret, new Comparator<Bin>() {
@Override
public int compare(Bin p1, Bin p2) {
return (int) (p1.widthLeft - p2.widthLeft); // Ascending
}
});
ret.sort(Comparator.comparingDouble(Bin::getwidthLeft)); //smallest to largest
}
else if(type.equals("Height"))
{
Collections.sort(ret, new Comparator<Bin>() {
@Override
public int compare(Bin p1, Bin p2) {
return (int) (p1.heightLeft - p2.heightLeft); // Ascending
}
});
ret.sort(Comparator.comparingDouble(Bin::getheightLeft)); //smallest to largest
}
if(typeOfOrder.equals("decreasing"))
Collections.reverse(ret); //decreasing
return ret;
}
public static boolean FitsToBin(Bin m, Item t)
{
if(m.heightLeft >= t.heightRequest && m.widthLeft >= t.widthRequest)
// if(m.totalCapacityLeft>=(t.CPUrequest*t.memoryRequest))
{
return true;
}
return false;
}
}