## UVa 102. Ecological Bin Packing | with Brute-force search

The UVa 102: Ecological Bin Packing can be solved using brute-force search, as outlined in the following Java code snippet. Note that, the primary function `getOPTConfiguration` iterates over all possible bin arrangements, and determines the arrangement that requires minimum bottle moves for a given problem instance.

 import java.io.PrintWriter; import java.util.Scanner; class Main { private Scanner in = new Scanner(System.in); private PrintWriter out = new PrintWriter(System.out, true); private char[] types; private int[][] permutations; private static final int _NO_OF_BINS = 3; private static final int _BOTTLE_TYPES = 3; private int optMoveCount; private String optPermutation; public Main(){ types = new char[]{'B','G','C'}; permutations = new int[][] { {0,1,2}, {0,2,1}, {1,0,2}, {1,2,0}, {2,0,1}, {2,1,0} }; } private String permutationString(int permutationIndex){ String retString = ""; for(int i = 0;i<_NO_OF_BINS;i++){ retString += types[permutations[permutationIndex][i]]; } return retString; } private void initState(){ optMoveCount = -1; optPermutation = ""; } /** * A brute-force algorithm to determine a bin * configuration that yield * optimal (minimum) bin movements. * @param input * @return a String that represents OPT bin * configuration that yields minimum movement. */ String getOPTConfiguration(int[][] input){ initState(); for (int pi = 0;pi
view raw uva102.java hosted with ❤ by GitHub