Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Readability -
What pieces of code help versus obscure your understanding of the algorithm?
The read data method helped my understanding, while
the the algorithm for sorting the bins obscured my understanding.
What comments might be helpful within the code?
Comments that explained and separated related chucks, such as printing the output,
or manipulating the queue.
Are there places where the code could be more concise and also more clear?
The main method was unnecessary long and unclear
Testability
How would you test this code for bugs?
Running specific text files with known correct outputs, and comparing it to our programs
output.
Give a specific example of a "test case" as the code is currently written.
Using the text file "example.txt" and the program's output
What additional functions may be helpful?

Give a specific example of a "test case" for your new function.
Extensibility

What Code Smells can you find?
The main function
What suggestions does this code make about how someone would extend it in the future to compare the performance of a wider variety of fitting algorithms?
What dependencies are there between different parts of the code?
How easy to find are those dependencies?
Can you clarify or remove those dependencies?
54 changes: 22 additions & 32 deletions src/Bins.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,47 +29,43 @@ public List<Integer> readData (Scanner input) {
/**
* The main program.
*/
public static int diskId = 1;
public static int total = 0;

public static void main (String args[]) {
Bins b = new Bins();
Scanner input = new Scanner(Bins.class.getClassLoader().getResourceAsStream(DATA_FILE));
List<Integer> data = b.readData(input);

PriorityQueue<Disk> pq = new PriorityQueue<Disk>();
pq.add(new Disk(0));

int diskId = 1;
int total = 0;
for (Integer size : data) {
Disk d = pq.peek();
if (d.freeSpace() > size) {
pq.poll();
d.add(size);
pq.add(d);
} else {
Disk d2 = new Disk(diskId);
diskId++;
d2.add(size);
pq.add(d2);
}
total += size;
}

worstFit(data, pq);
System.out.println("total size = " + total / 1000000.0 + "GB");
System.out.println();
System.out.println("worst-fit method");
System.out.println("number of pq used: " + pq.size());
pqPrint(pq);

Collections.sort(data, Collections.reverseOrder());
pq = worstFit(data, pq);

System.out.println();
System.out.println("worst-fit decreasing method");
pqPrint(pq);
}


public static void pqPrint(PriorityQueue<Disk> pq){
System.out.println("number of pq used: " + pq.size());
while (!pq.isEmpty()) {
System.out.println(pq.poll());
}
System.out.println();
}

Collections.sort(data, Collections.reverseOrder());
public static PriorityQueue<Disk> worstFit(List<Integer> data, PriorityQueue<Disk> pq ){
pq.add(new Disk(0));

diskId = 1;
for (Integer size : data) {
Disk d = pq.peek();
if (d.freeSpace() >= size) {
if (d.freeSpace() > size) {
pq.poll();
d.add(size);
pq.add(d);
Expand All @@ -79,14 +75,8 @@ public static void main (String args[]) {
d2.add(size);
pq.add(d2);
}
total += size;
}

System.out.println();
System.out.println("worst-fit decreasing method");
System.out.println("number of pq used: " + pq.size());
while (!pq.isEmpty()) {
System.out.println(pq.poll());
}
System.out.println();
return pq;
}
}