Question
Can someone help me figure out how to edit these java classes in order to use optimization? This is in IntelliJ with gradle. Consider the
Can someone help me figure out how to edit these java classes in order to use optimization? This is in IntelliJ with gradle.
Consider the following optimization problem:
Notice that this version of the 0-1 knapsack problem contains 2 knapsacks. That is, if you include an item, it must fit in both the knapsack with capacity c and in the knapsack with capacity d.
a. Modify the class KP2ItemInfo so that it binds the columns in Item_Data.csv to fields in the class using OpenCSV.
File: H3_Q1.java ------------------ import com.opencsv.bean.CsvToBeanBuilder; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.LinkedList; import java.util.List; public class H3_Q1 { public static void main(String[] args) throws FileNotFoundException { LinkedListitems = new LinkedList(); int c = 11; int d =10; //Uncomment line below once loadProblem method is complete //loadProblem(items); } }
---------------------------------------------------------------------------------------------------------
File: H3_Q2.java
------------------
import com.opencsv.bean.CsvToBeanBuilder; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.LinkedList; import java.util.List; public class H3_Q2 { public static void main(String[] args) throws FileNotFoundException { LinkedListitems = new LinkedList(); int c = 9; //Uncomment line below once loadProblem method is complete // loadProblem(items); } }
------------------------------------------------------------------------------------------------------------------
File: H3_Q3.java
-----------------
import java.util.ArrayList; import java.util.Collections; public class H3_Q3 { public static void main(String[] args) { //0/1 KP attributes int C = 10; //knapsack capacity ArrayListitems = new ArrayList(); //hold possible items to include in knapsack KPItem ki = new KPItem(3, 6); items.add(ki); ki = new KPItem(5, 7); items.add(ki); ki = new KPItem(1, 3); items.add(ki) ki = new KPItem(8, 10); items.add(ki); ArrayList solution = new ArrayList(Collections.nCopies(items.size(), 0)); //initialize all zeroes, stores 0/1 decisions //Uncomment line below once your knapsack method is included in the class //System.out.println("Optimal Objective Value: " + knapsack(items, items.size() - 1, C,solution)); } }
--------------------------------------------------------------------------------------------------------------
File: KP2Item.java
--------------------------
public class KP2Item { //declare fields associated with an item for the problem given in Q1 //Constructors }
--------------------------------------------------------------------------------------------------------------
File: KP2ItemInfo.java
--------------------------
import com.opencsv.bean.CsvBindByName; public class KP2ItemInfo { }
--------------------------------------------------------------------------------------------------------------
File: KPItem.java
--------------------------
public class KPItem{ //declare fields associated with an item for the problem given in Q2 }
--------------------------------------------------------------------------------------------------------------
File: KPItemInfo.java
--------------------------
import com.opencsv.bean.CsvBindByName; public class KPItemInfo { }
--------------------------------------------------------------------------------------------------------------
File: build.gradle
--------------------------
repositories { mavenCentral() } dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' // https://mvnrepository.com/artifact/com.opencsv/opencsv compile group: 'com.opencsv', name: 'opencsv', version: '5.1' }
--------------------------------------------------------------------------------------------------------------
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started