Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.image text in transcribedimage text in transcribedimage text in transcribed

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 { LinkedList items = 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 { LinkedList items = 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 ArrayList items = 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' }

--------------------------------------------------------------------------------------------------------------

Don't know of the gradle file needs to be changed at all.
Consider the following optimization problem: max vilj s.t. Zv;?; sc WIEWIWI w;!; sd X; {0,1} 15jsn 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. Data.csv to fields in the class using a. Modify the class KP2ItemInfo so that it binds the columns in Item OpenCSV. b. Add to the class KP2Item appropriate constructers and fields for v, w, and p in the problem given above. c. In H3_Q1, write a static method called loadProblem with the following properties: arguments: Linked List named items containing objects of type KP2Item return: nothing functionality reads: values from Item Data.csv and adds them to items d. In H3_Q1, write a static method called solveKP2 that solves the 2-knapsack problem and returns an integer. The method should be recursive. You should determine what arguments the method accepts (hint: think about how we handled the 1-knapsack problem in class and expand upon it). e. In H3_Q1, add a line of code to the end of the main method that outputs the optimal solution to the 2-knapsack problem. Consider the following optimization problem: max Vilj j=1 s.t.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions