Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging #1

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
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
21 changes: 15 additions & 6 deletions MultiObj/.classpath
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="C:/Users/charl/Google Drive/CES5/CS547/opt4j-3.1.4/opt4j-3.1.4/lib/guice-4.0-beta5.jar"/>
<classpathentry kind="lib" path="C:/Users/charl/Google Drive/CES5/CS547/opt4j-3.1.4/opt4j-3.1.4/lib/guice-multibindings-4.0-beta5.jar"/>
<classpathentry kind="lib" path="C:/Users/charl/Google Drive/CES5/CS547/opt4j-3.1.4/opt4j-3.1.4/lib/opt4j-core-3.1.4.jar"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="C:/Users/charl/Desktop/opt4j-3.1.4/opt4j-3.1.4/lib/guice-4.0-beta5.jar"/>
<classpathentry kind="lib" path="C:/Users/charl/Desktop/opt4j-3.1.4/opt4j-3.1.4/lib/opt4j-core-3.1.4.jar"/>
<classpathentry kind="lib" path="C:/Users/charl/Desktop/opt4j-3.1.4/opt4j-3.1.4/lib/guice-multibindings-4.0-beta5.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
1 change: 1 addition & 0 deletions MultiObj/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/bin/
/target/
1 change: 1 addition & 0 deletions MultiObj/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8
1 change: 1 addition & 0 deletions MultiObj/src/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public class Constants {
public static final int COST_RATIO = 0;
public static final String FILE_NAME = "nrp1.txt";
public static final Boolean DEBUG = false;
public static final Boolean DEBUG_SCORES = true;

}
10 changes: 0 additions & 10 deletions MultiObj/src/Creator.java

This file was deleted.

10 changes: 0 additions & 10 deletions MultiObj/src/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ public class Customer {

private int profit = 0;
private int Numrequests = 0;
private int customerLabel = 0;
private List<Integer> reqList = new ArrayList<Integer>();

/**
Expand All @@ -19,7 +18,6 @@ public Customer(int profit, int Numrequests, List<Integer> reqList, int customer
this.setProfit(profit);
this.setNumRequests(Numrequests);
this.setReqList(reqList);
this.setCustomerLabel(customerLabel);
}

/**
Expand All @@ -29,14 +27,6 @@ public Customer() {

}

public int getCustomerLabel() {
return customerLabel;
}

public void setCustomerLabel(int customerLabel) {
this.customerLabel = customerLabel;
}

public int getProfit() {
return profit;
}
Expand Down
4 changes: 0 additions & 4 deletions MultiObj/src/Decoder.java

This file was deleted.

11 changes: 0 additions & 11 deletions MultiObj/src/Demo.java

This file was deleted.

4 changes: 0 additions & 4 deletions MultiObj/src/Evaluator.java

This file was deleted.

67 changes: 51 additions & 16 deletions MultiObj/src/FileParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -22,19 +25,23 @@ public class FileParser {
public List<Integer> IDReqA = new ArrayList<Integer>();
public List<Integer> IDReqB = new ArrayList<Integer>();
public List<Requirements> level = new ArrayList<Requirements>();
public List<Integer> allCosts = new ArrayList<Integer>();

/**
* Parsing the file into something more useful
*
* @return
*/
public void parseFile() {
public NRP parseFile() {

BufferedReader br = null;
String currentLine;
int counter = 0;
int customerCount = 0;

try {
br = new BufferedReader(new FileReader(Constants.FILE_NAME));
File file = new File("C:/Users/charl/Desktop/nrp1.txt");
br = new BufferedReader(new FileReader(file));
while ((currentLine = br.readLine()) != null) {
counter++; // Skips line 0
if (counter == 1) {
Expand All @@ -48,18 +55,22 @@ public void parseFile() {
List<String> tokensList = new ArrayList<String>(Arrays.asList(tokens));
if (tokens.length > 1) {
// save as whatever
System.out.println(currentLine + " is current line");
System.out.println(tokensList.size() + " is size");
if (Constants.DEBUG) {
System.out.println(currentLine + " is current line");
System.out.println(tokensList.size() + " is size");
}
Requirements r = new Requirements(tokensList.size(), tokensList, countBoop);
level.add(r);
countBoop++; // Just to add level to Requirements
// object
addtoTotalCost(tokensList);
countBoop++;
}
reqCounter--;

}
nrp.setRequirements(level);
System.out.println("should be num dependancies.. " + br.readLine());
if (Constants.DEBUG == true) {
System.out.println("should be num dependancies.. " + br.readLine());
}
}

// Go through all the ID's
Expand All @@ -73,12 +84,16 @@ public void parseFile() {
nrp.setIDReqB(IDReqB);

// Customer attributes
while (words > 2) {
while (words > 2 && words < 14) {
/**
* May need to change the < value depending on dataset
*/
customerCount++;
customerAttributeExtraction(customerCount, currentLine);
words = 0;
}
nrp.setCustomers(customersList);

}
nrp.setNumCustomers(customerCount);

Expand All @@ -90,6 +105,16 @@ public void parseFile() {
e.printStackTrace();
}
debug(); // Make sure everything has went into the correct objects

return nrp;
}

private void addtoTotalCost(List<String> annoyingList) {
for (String n : annoyingList) {
int nm = Integer.parseInt(n);
allCosts.add(nm);
nrp.setAllCosts(allCosts);
}
}

/**
Expand All @@ -110,16 +135,19 @@ private void IDExtraction(String currentLine) {
private void customerAttributeExtraction(int customerCount, String currentLine) {
// Just to keep track of the right things..
Customer customer = new Customer();
customer.setCustomerLabel(customerCount);

// Split line into different attributes
String[] tokens = currentLine.split("\\s+");
customer.setProfit(Integer.parseInt(tokens[0]));
customer.setNumRequests(Integer.parseInt(tokens[1]));
String[] subTokens = Arrays.copyOfRange(tokens, 2, tokens.length);
List<Integer> reqList = new ArrayList<Integer>();

for (String s : subTokens) {
reqList.add(Integer.parseInt(s));
if (Constants.DEBUG == true) {
System.out.println("bapitty boopity: " + Integer.parseInt(s));
}
}
customer.setReqList(reqList);
customersList.add(customer);
Expand All @@ -137,11 +165,6 @@ private void debug() {
System.out.println(nrp.getNumCustomers() + " is num customers in object");
System.out.println(nrp.getNumReq() + "is number requirements");

System.out.println("customers list: ");
for (Customer c : nrp.getCustomers()) {
System.out.println(c.getCustomerLabel());
}

System.out.println("Requirements A list");
for (Integer s : nrp.getIDReqA()) {
System.out.println(s);
Expand All @@ -159,6 +182,11 @@ private void debug() {
System.out.println(n.getLevel() + " : is level ");
}

System.out.println("aw the costs");
for (Integer n : allCosts) {
System.out.println(n);
}

}
}

Expand All @@ -174,7 +202,7 @@ public int tokenizeShit(String currentLine) {
int total = tokens.length;
return total;
}

/**
* May need to put each different object into different methods Still need
* to add every parsed bit into customer objects and such and also link the
Expand All @@ -184,7 +212,14 @@ public int tokenizeShit(String currentLine) {
* @throws IOException
*/
public static void main(String[] args) throws IOException {

FileParser fp = new FileParser();
fp.parseFile();
System.out.println("boop");
NRP nrp = fp.parseFile();

for (Customer n : nrp.getCustomers()) {
System.out.println(n.getProfit() + " " + n.getReqList());
}

}
}
9 changes: 9 additions & 0 deletions MultiObj/src/NRP.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class NRP {
private List<Integer> IDReqB = new ArrayList<Integer>();
private List<Customer> customers = new ArrayList<Customer>();
private List<Requirements> requirements = new ArrayList<Requirements>();
private List<Integer> allCosts = new ArrayList<Integer>();

/**
* Basically I am lazy and would like the option to make this in any
Expand Down Expand Up @@ -190,4 +191,12 @@ public void setRequirements(List<Requirements> level) {
this.requirements = level;
}

public List<Integer> getAllCosts() {
return allCosts;
}

public void setAllCosts(List<Integer> allCosts) {
this.allCosts = allCosts;
}

}
23 changes: 23 additions & 0 deletions MultiObj/src/NRPBOOPCreator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

import java.util.Random;
import org.opt4j.core.problem.Creator;
import org.opt4j.core.genotype.BooleanGenotype;

/**
* Create instances of a solution
*
* @author Charlotte Wilson
*
*/
public class NRPBOOPCreator implements Creator<BooleanGenotype> {
Random random = new Random();

public BooleanGenotype create() {
BooleanGenotype genotype = new BooleanGenotype();
/**
* Need to change this to the same number of requirements?
*/
genotype.init(random, 140); //
return genotype;
}
}
23 changes: 23 additions & 0 deletions MultiObj/src/NRPBOOPDecoder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

import org.opt4j.core.problem.Decoder;
import org.opt4j.core.genotype.BooleanGenotype;

/**
* Changes Boolean phenotype to a string phenotype
*
* @author Charlotte Wilson
*
*/
public class NRPBOOPDecoder implements Decoder<BooleanGenotype, String> {
public String decode(BooleanGenotype genotype) {
String phenotype = "";
for (int i = 0; i < genotype.size(); i++) {
// True for requirement is selected
if (genotype.get(i) == true)
phenotype += "1";
else
phenotype += "0";
}
return phenotype;
}
}
Loading