List of usage examples for org.apache.poi.ss.usermodel Workbook write
void write(OutputStream stream) throws IOException;
From source file:info.informationsea.venn.CombinationImporterExporter.java
License:Open Source License
public static <T, U> void export(File file, CombinationSolver<T, U> combinationSolver, List<VennFigureParameters.Attribute<T>> keyList) throws Exception { if (file.getName().endsWith(".csv")) { try (FileWriter writer = new FileWriter(file); TableCSVWriter csvWriter = new TableCSVWriter(writer)) { export(csvWriter, combinationSolver, keyList); }/*from w w w .j a v a2s. c o m*/ } else if (file.getName().endsWith(".xlsx") || file.getName().endsWith(".xls")) { Workbook workbook; if (file.getName().endsWith(".xlsx")) workbook = new SXSSFWorkbook(); else workbook = new HSSFWorkbook(); // Export dataset Sheet sheet = workbook.createSheet("Data"); try (ExcelSheetWriter writer = new ExcelSheetWriter(sheet)) { writer.setPrettyTable(true); export(writer, combinationSolver, keyList); } // Export combinations sheet = workbook.createSheet("Combinations"); try (ExcelSheetWriter writer = new ExcelSheetWriter(sheet)) { writer.setPrettyTable(false); writer.setEnableHeaderStyle(true); writer.setAlternativeBackground(true); writer.printRecord("Combination", "# of items", "items"); for (Map.Entry<Set<T>, Set<U>> entry : combinationSolver.getCombinationResult().entrySet()) { String keys = ""; for (T one : entry.getKey()) { if (keys.length() > 0) keys += ", "; keys += one.toString(); } List<Object> row = new ArrayList<>(); row.add(keys); row.add(entry.getValue().size()); for (U one : entry.getValue()) { row.add(one.toString()); } writer.printRecord(row.toArray()); } } // Export venn diagram switch (combinationSolver.getValues().size()) { case 2: case 3: case 4: ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); VennExporter.exportAsPNG(new VennFigureParameters<T>(combinationSolver, keyList), outputStream, 800, 10); outputStream.close(); sheet = workbook.createSheet("Venn"); try (ExcelImageSheetWriter imageSheetWriter = new ExcelImageSheetWriter(sheet)) { imageSheetWriter.addImage(ImageSheetWriter.ImageType.TYPE_PNG, outputStream.toByteArray()); } break; default: // Do nothing break; } try (FileOutputStream fos = new FileOutputStream(file)) { workbook.write(fos); } } else { throw new IllegalArgumentException("Unsupported file type"); } }
From source file:instancegenerator.ExcelGenerator.java
public static void makeInstancesN100S1() { int weight = 0; int capacity = 0; int cost = 0; int[] items = new int[100]; try {/*from w w w.ja v a2 s .co m*/ //**************** Class A *************************************************** //instance A1 FileOutputStream fileout = new FileOutputStream(new File("src/instances/Set1/N100/N100A1.xls")); Workbook ficheroWb = new HSSFWorkbook(); Sheet sheet = ficheroWb.createSheet("Instance A1 for VSBPP"); Row row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); //for the items int reqCapacity = 0; for (int i = 1; i <= 100; i++) { weight = (int) randVal(1, 20); items[i - 1] = weight; reqCapacity += weight; row = sheet.createRow(i); row.createCell(2).setCellValue(weight); } // for the bins int cap = 100; int j = 1; for (int i = 1; i <= 3; i++) { int availableCap = 0; capacity = cap * i; cost = (int) (100 * Math.sqrt(capacity)); while (availableCap < reqCapacity) { row = sheet.getRow(j); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance A2 fileout = new FileOutputStream(new File("src/instances/Set1/N100/N100A2.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance A2 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 100; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 50; j = 1; for (int i = 1; i <= 6; i++) { int availableCap = 0; capacity = cap * i; cost = (int) (100 * Math.sqrt(capacity)); while (availableCap < reqCapacity) { row = sheet.getRow(j); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance A3 fileout = new FileOutputStream(new File("src/instances/Set1/N100/N100A3.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance A3 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 100; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 25; j = 1; for (int i = 1; i <= 12; i++) { int availableCap = 0; capacity = cap * i; cost = (int) (100 * Math.sqrt(capacity)); while (availableCap < reqCapacity) { row = sheet.getRow(j); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance A4 fileout = new FileOutputStream(new File("src/instances/Set1/N100/N100A4.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance A4 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 100; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 60; j = 1; for (int i = 1; i <= 55; i++) { capacity = cap; cost = (int) (100 * Math.sqrt(capacity)); row = sheet.getRow(i); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); cap = cap + 5; } ficheroWb.write(fileout); fileout.flush(); capacity = 0; } catch (IOException ex) { System.out.println(ex.getMessage()); } }
From source file:instancegenerator.ExcelGenerator.java
public static void makeInstancesN200S1() { int weight = 0; int capacity = 0; int cost = 0; int[] items = new int[200]; try {/* ww w . j a va 2 s. co m*/ //**************** Class A *************************************************** //instance A1 FileOutputStream fileout = new FileOutputStream(new File("src/instances/Set1/N200/N200A1.xls")); Workbook ficheroWb = new HSSFWorkbook(); Sheet sheet = ficheroWb.createSheet("Instance A1 for VSBPP"); Row row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); //for the items int reqCapacity = 0; for (int i = 1; i <= 200; i++) { weight = (int) randVal(1, 20); items[i - 1] = weight; reqCapacity += weight; row = sheet.createRow(i); row.createCell(2).setCellValue(weight); } // for the bins int cap = 100; int j = 1; for (int i = 1; i <= 3; i++) { int availableCap = 0; capacity = cap * i; cost = (int) (100 * Math.sqrt(capacity)); while (availableCap < reqCapacity) { row = sheet.getRow(j); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance A2 fileout = new FileOutputStream(new File("src/instances/Set1/N200/N200A2.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance A2 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 200; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 50; j = 1; for (int i = 1; i <= 6; i++) { int availableCap = 0; capacity = cap * i; cost = (int) (100 * Math.sqrt(capacity)); while (availableCap < reqCapacity) { row = sheet.getRow(j); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance A3 fileout = new FileOutputStream(new File("src/instances/Set1/N200/N200A3.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance A3 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 200; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 25; j = 1; for (int i = 1; i <= 12; i++) { int availableCap = 0; capacity = cap * i; cost = (int) (100 * Math.sqrt(capacity)); while (availableCap < reqCapacity) { row = sheet.getRow(j); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance A4 fileout = new FileOutputStream(new File("src/instances/Set1/N200/N200A4.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance A4 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 200; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 60; j = 1; for (int i = 1; i <= 55; i++) { capacity = cap; cost = (int) (100 * Math.sqrt(capacity)); row = sheet.getRow(i); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); cap = cap + 5; } ficheroWb.write(fileout); fileout.flush(); capacity = 0; } catch (IOException ex) { System.out.println(ex.getMessage()); } }
From source file:instancegenerator.ExcelGenerator.java
public static void makeInstancesN500S1() { int weight = 0; int capacity = 0; int cost = 0; int[] items = new int[500]; try {/*from w w w . j a v a2s . c o m*/ //**************** Class A *************************************************** //instance A1 FileOutputStream fileout = new FileOutputStream(new File("src/instances/Set1/N500/N500A1.xls")); Workbook ficheroWb = new HSSFWorkbook(); Sheet sheet = ficheroWb.createSheet("Instance A1 for VSBPP"); Row row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); //for the items int reqCapacity = 0; for (int i = 1; i <= 500; i++) { weight = (int) randVal(1, 20); items[i - 1] = weight; reqCapacity += weight; row = sheet.createRow(i); row.createCell(2).setCellValue(weight); } // for the bins int cap = 100; int j = 1; for (int i = 1; i <= 3; i++) { int availableCap = 0; capacity = cap * i; cost = (int) (100 * Math.sqrt(capacity)); while (availableCap < reqCapacity) { row = sheet.getRow(j); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance A2 fileout = new FileOutputStream(new File("src/instances/Set1/N500/N500A2.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance A2 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 500; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 50; j = 1; for (int i = 1; i <= 6; i++) { int availableCap = 0; capacity = cap * i; cost = (int) (100 * Math.sqrt(capacity)); while (availableCap < reqCapacity) { row = sheet.getRow(j); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance A3 fileout = new FileOutputStream(new File("src/instances/Set1/N500/N500A3.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance A3 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 500; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 25; j = 1; for (int i = 1; i <= 12; i++) { int availableCap = 0; capacity = cap * i; cost = (int) (100 * Math.sqrt(capacity)); while (availableCap < reqCapacity) { row = sheet.getRow(j); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance A4 fileout = new FileOutputStream(new File("src/instances/Set1/N500/N500A4.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance A4 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 500; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 60; j = 1; for (int i = 1; i <= 55; i++) { capacity = cap; cost = (int) (100 * Math.sqrt(capacity)); row = sheet.getRow(i); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); cap = cap + 5; } ficheroWb.write(fileout); fileout.flush(); capacity = 0; } catch (IOException ex) { System.out.println(ex.getMessage()); } }
From source file:instancegenerator.ExcelGenerator.java
public static void makeInstancesN1000S1() { int weight = 0; int capacity = 0; int cost = 0; int[] items = new int[1000]; try {//from w w w . jav a 2 s . c o m //**************** Class A *************************************************** //instance A1 FileOutputStream fileout = new FileOutputStream(new File("src/instances/Set1/N1000/N1000A1.xls")); Workbook ficheroWb = new HSSFWorkbook(); Sheet sheet = ficheroWb.createSheet("Instance A1 for VSBPP"); Row row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); //for the items int reqCapacity = 0; for (int i = 1; i <= 1000; i++) { weight = (int) randVal(1, 20); items[i - 1] = weight; reqCapacity += weight; row = sheet.createRow(i); row.createCell(2).setCellValue(weight); } // for the bins int cap = 100; int j = 1; for (int i = 1; i <= 3; i++) { int availableCap = 0; capacity = cap * i; cost = (int) (100 * Math.sqrt(capacity)); while (availableCap < reqCapacity) { row = sheet.getRow(j); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance A2 fileout = new FileOutputStream(new File("src/instances/Set1/N1000/N1000A2.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance A2 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 1000; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 50; j = 1; for (int i = 1; i <= 6; i++) { int availableCap = 0; capacity = cap * i; cost = (int) (100 * Math.sqrt(capacity)); while (availableCap < reqCapacity) { row = sheet.getRow(j); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance A3 fileout = new FileOutputStream(new File("src/instances/Set1/N1000/N1000A3.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance A3 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 1000; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 25; j = 1; for (int i = 1; i <= 12; i++) { int availableCap = 0; capacity = cap * i; cost = (int) (100 * Math.sqrt(capacity)); while (availableCap < reqCapacity) { row = sheet.getRow(j); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance A4 fileout = new FileOutputStream(new File("src/instances/Set1/N1000/N1000A4.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance A4 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 1000; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 60; j = 1; for (int i = 1; i <= 55; i++) { capacity = cap; cost = (int) (100 * Math.sqrt(capacity)); row = sheet.getRow(i); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); cap = cap + 5; } ficheroWb.write(fileout); fileout.flush(); capacity = 0; } catch (IOException ex) { System.out.println(ex.getMessage()); } }
From source file:instancegenerator.ExcelGenerator.java
/******************* No function asociated to cost of bins ********************************/ public static void makeInstancesN100S2() { int weight = 0; int capacity = 0; int cost = 0; int[] items = new int[100]; try {/* w ww . ja v a 2 s . c o m*/ //**************** Class B *************************************************** //instance B1 FileOutputStream fileout = new FileOutputStream(new File("src/instances/Set2/N100/N100B1.xls")); Workbook ficheroWb = new HSSFWorkbook(); Sheet sheet = ficheroWb.createSheet("Instance B1 for VSBPP"); Row row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); //for the items int reqCapacity = 0; for (int i = 1; i <= 100; i++) { weight = (int) randVal(1, 20); items[i - 1] = weight; reqCapacity += weight; row = sheet.createRow(i); row.createCell(2).setCellValue(weight); } // for the bins int cap = 100; int j = 1; for (int i = 1; i <= 3; i++) { int availableCap = 0; capacity = cap * i; while (availableCap < reqCapacity) { row = sheet.getRow(j); double y = randValueReal(0.05, 0.3); cost = (int) ((100 * Math.sqrt(capacity)) * (1 + y)); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance B2 fileout = new FileOutputStream(new File("src/instances/Set2/N100/N100B2.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance B2 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 100; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 50; j = 1; for (int i = 1; i <= 6; i++) { int availableCap = 0; capacity = cap * i; while (availableCap < reqCapacity) { row = sheet.getRow(j); double y = randValueReal(0.05, 0.3); cost = (int) ((100 * Math.sqrt(capacity)) * (1 + y)); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance B3 fileout = new FileOutputStream(new File("src/instances/Set2/N100/N100B3.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance B3 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 100; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 25; j = 1; for (int i = 1; i <= 12; i++) { int availableCap = 0; capacity = cap * i; while (availableCap < reqCapacity) { row = sheet.getRow(j); double y = randValueReal(0.05, 0.3); cost = (int) ((100 * Math.sqrt(capacity)) * (1 + y)); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance B4 fileout = new FileOutputStream(new File("src/instances/Set2/N100/N100B4.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance B4 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 100; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 60; j = 1; for (int i = 1; i <= 55; i++) { capacity = cap; double y = randValueReal(0.05, 0.3); cost = (int) ((100 * Math.sqrt(capacity)) * (1 + y)); row = sheet.getRow(i); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); cap = cap + 5; } ficheroWb.write(fileout); fileout.flush(); capacity = 0; } catch (IOException ex) { System.out.println(ex.getMessage()); } }
From source file:instancegenerator.ExcelGenerator.java
public static void makeInstancesN200S2() { int weight = 0; int capacity = 0; int cost = 0; int[] items = new int[200]; try {// ww w . j a va 2 s.c om //**************** Class B *************************************************** //instance B1 FileOutputStream fileout = new FileOutputStream(new File("src/instances/Set2/N200/N200B1.xls")); Workbook ficheroWb = new HSSFWorkbook(); Sheet sheet = ficheroWb.createSheet("Instance B1 for VSBPP"); Row row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); //for the items int reqCapacity = 0; for (int i = 1; i <= 200; i++) { weight = (int) randVal(1, 20); items[i - 1] = weight; reqCapacity += weight; row = sheet.createRow(i); row.createCell(2).setCellValue(weight); } // for the bins int cap = 100; int j = 1; for (int i = 1; i <= 3; i++) { int availableCap = 0; capacity = cap * i; double y = randValueReal(0.05, 0.3); cost = (int) ((100 * Math.sqrt(capacity)) * (1 + y)); while (availableCap < reqCapacity) { row = sheet.getRow(j); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance B2 fileout = new FileOutputStream(new File("src/instances/Set2/N200/N200B2.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance B2 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 200; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 50; j = 1; for (int i = 1; i <= 6; i++) { int availableCap = 0; capacity = cap * i; double y = randValueReal(0.05, 0.3); cost = (int) ((100 * Math.sqrt(capacity)) * (1 + y)); while (availableCap < reqCapacity) { row = sheet.getRow(j); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance B3 fileout = new FileOutputStream(new File("src/instances/Set2/N200/N200B3.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance B3 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 200; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 25; j = 1; for (int i = 1; i <= 12; i++) { int availableCap = 0; capacity = cap * i; double y = randValueReal(0.05, 0.3); cost = (int) ((100 * Math.sqrt(capacity)) * (1 + y)); while (availableCap < reqCapacity) { row = sheet.getRow(j); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance B4 fileout = new FileOutputStream(new File("src/instances/Set2/N200/N200B4.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance B4 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 200; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 60; j = 1; for (int i = 1; i <= 55; i++) { capacity = cap; double y = randValueReal(0.05, 0.3); cost = (int) ((100 * Math.sqrt(capacity)) * (1 + y)); row = sheet.getRow(i); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); cap = cap + 5; } ficheroWb.write(fileout); fileout.flush(); capacity = 0; } catch (IOException ex) { System.out.println(ex.getMessage()); } }
From source file:instancegenerator.ExcelGenerator.java
public static void makeInstancesN500S2() { int weight = 0; int capacity = 0; int cost = 0; int[] items = new int[500]; try {/* w w w .ja v a 2 s.c om*/ //**************** Class B *************************************************** //instance B1 FileOutputStream fileout = new FileOutputStream(new File("src/instances/Set2/N500/N500B1.xls")); Workbook ficheroWb = new HSSFWorkbook(); Sheet sheet = ficheroWb.createSheet("Instance B1 for VSBPP"); Row row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); //for the items int reqCapacity = 0; for (int i = 1; i <= 500; i++) { weight = (int) randVal(1, 20); items[i - 1] = weight; reqCapacity += weight; row = sheet.createRow(i); row.createCell(2).setCellValue(weight); } // for the bins int cap = 100; int j = 1; for (int i = 1; i <= 3; i++) { int availableCap = 0; capacity = cap * i; while (availableCap < reqCapacity) { row = sheet.getRow(j); double y = randValueReal(0.05, 0.3); cost = (int) ((100 * Math.sqrt(capacity)) * (1 + y)); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance B2 fileout = new FileOutputStream(new File("src/instances/Set2/N500/N500B2.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance B2 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 500; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 50; j = 1; for (int i = 1; i <= 6; i++) { int availableCap = 0; capacity = cap * i; while (availableCap < reqCapacity) { row = sheet.getRow(j); double y = randValueReal(0.05, 0.3); cost = (int) ((100 * Math.sqrt(capacity)) * (1 + y)); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance B3 fileout = new FileOutputStream(new File("src/instances/Set2/N500/N500B3.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance B3 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 500; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 25; j = 1; for (int i = 1; i <= 12; i++) { int availableCap = 0; capacity = cap * i; while (availableCap < reqCapacity) { row = sheet.getRow(j); double y = randValueReal(0.05, 0.3); cost = (int) ((100 * Math.sqrt(capacity)) * (1 + y)); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance B4 fileout = new FileOutputStream(new File("src/instances/Set2/N500/N500B4.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance A4 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 500; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 60; j = 1; for (int i = 1; i <= 55; i++) { capacity = cap; double y = randValueReal(0.05, 0.3); cost = (int) ((100 * Math.sqrt(capacity)) * (1 + y)); row = sheet.getRow(i); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); cap = cap + 5; } ficheroWb.write(fileout); fileout.flush(); capacity = 0; } catch (IOException ex) { System.out.println(ex.getMessage()); } }
From source file:instancegenerator.ExcelGenerator.java
public static void makeInstancesN1000S2() { int weight = 0; int capacity = 0; int cost = 0; int[] items = new int[1000]; try {//from www. ja v a 2s. c o m //**************** Class B *************************************************** //instance B1 FileOutputStream fileout = new FileOutputStream(new File("src/instances/Set2/N1000/N1000B1.xls")); Workbook ficheroWb = new HSSFWorkbook(); Sheet sheet = ficheroWb.createSheet("Instance B1 for VSBPP"); Row row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); //for the items int reqCapacity = 0; for (int i = 1; i <= 1000; i++) { weight = (int) randVal(1, 20); items[i - 1] = weight; reqCapacity += weight; row = sheet.createRow(i); row.createCell(2).setCellValue(weight); } // for the bins int cap = 100; int j = 1; for (int i = 1; i <= 3; i++) { int availableCap = 0; capacity = cap * i; while (availableCap < reqCapacity) { row = sheet.getRow(j); double y = randValueReal(0.05, 0.3); cost = (int) ((100 * Math.sqrt(capacity)) * (1 + y)); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance B2 fileout = new FileOutputStream(new File("src/instances/Set2/N1000/N1000B2.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance B2 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 1000; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 50; j = 1; for (int i = 1; i <= 6; i++) { int availableCap = 0; capacity = cap * i; while (availableCap < reqCapacity) { row = sheet.getRow(j); double y = randValueReal(0.05, 0.3); cost = (int) ((100 * Math.sqrt(capacity)) * (1 + y)); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance B3 fileout = new FileOutputStream(new File("src/instances/Set2/N1000/N1000B3.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance A3 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 1000; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 25; j = 1; for (int i = 1; i <= 12; i++) { int availableCap = 0; capacity = cap * i; while (availableCap < reqCapacity) { row = sheet.getRow(j); double y = randValueReal(0.05, 0.3); cost = (int) ((100 * Math.sqrt(capacity)) * (1 + y)); if (row != null) { row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } else { row = sheet.createRow(j); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); } j++; availableCap = availableCap + capacity; } } ficheroWb.write(fileout); fileout.flush(); capacity = 0; //instance B4 fileout = new FileOutputStream(new File("src/instances/Set2/N1000/N1000B4.xls")); ficheroWb = new HSSFWorkbook(); sheet = ficheroWb.createSheet("Instance B4 for VSBPP"); row = sheet.createRow(0); row.createCell(0).setCellValue("Capacity"); row.createCell(1).setCellValue("Cost"); row.createCell(2).setCellValue("Weight"); // for the items for (int i = 1; i <= 1000; i++) { row = sheet.createRow(i); row.createCell(2).setCellValue(items[i - 1]); } //for the bins cap = 60; j = 1; for (int i = 1; i <= 55; i++) { capacity = cap; double y = randValueReal(0.05, 0.3); cost = (int) ((100 * Math.sqrt(capacity)) * (1 + y)); row = sheet.getRow(i); row.createCell(0).setCellValue(capacity); row.createCell(1).setCellValue(cost); cap = cap + 5; } ficheroWb.write(fileout); fileout.flush(); capacity = 0; } catch (IOException ex) { System.out.println(ex.getMessage()); } }
From source file:IO.FILES.java
final void save(Workbook wb) throws FileNotFoundException, IOException { FileOutputStream fl = new FileOutputStream(new File(ruta)); wb.write(fl); fl.flush();//from w w w. j a v a 2s .co m fl.close(); }