Need help with weighted interval scheduling problem.
This is what I have for my program so far.
Code:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;
public class WeightedIntervalScheduling {
public static void main(String[] args) throws FileNotFoundException {
int i,j;
String FileName;
FileName = "Intervals.txt";
File f = new File(FileName);
Scanner fileIn = new Scanner(f);
int[] Start = new int[100];
int[] Finish = new int[100];
int[] Weight = new int[100];
i = 0;
while (fileIn.hasNext()) {
Start[i] = fileIn.nextInt();
Finish[i] = fileIn.nextInt();
Weight[i] = fileIn.nextInt();
i++;
}
i = 0;
while (i < 9){
System.out.println(Start[i] + ", " + Finish[i] + ", " + Weight[i]);
i++;
}
//just input
int Jobs[] = new int[8];
j=0;
i=0;
while(i!=7){
Jobs[i] = i;
i++;}
int M[] = new int[8];
int p[] = new int[8];
i=0; j=0;
while(j!=8){
i=0;
while(i!=8){
if(Start[j] >= Finish[i]){
p[j]=Math.max(Finish[i], Start[j]);
}
i++;
}
j++;
}
j=0;
while(j<=7){
if(j==0){M[j] = 0;}
if(j>0){M[j]= Math.max(Weight[j]+ Weight[p[j]], M[j-1]);}
j++;
}
System.out.println(Arrays.toString(p));
System.out.println(Arrays.toString(M));
System.out.println("Optimal Value: " + p[7]);
}
}
It reads in the intervals (already sorted by finish time) from a text file and is suppose to find the optimal schedule. When changing the weight in the text file it does not change the result of the program. The program is suppose to use recursion and memorization to go through the intervals and find the optimal one. I am really lost at this point anything to help me out would be greatly appreciated.
Re: Need help with weighted interval scheduling problem.
Can you describe the problem you're trying to solve? (not your implementation (it doesn't work as it is now) ;-)
kind regards,
Jos
Re: Need help with weighted interval scheduling problem.
I've written an explanation of the problem, its complexity analysis and provided C++ code here: Weighted Interval Scheduling Problem | Everything Under The Sun
Re: Need help with weighted interval scheduling problem.
Quote:
Originally Posted by
kartikkukreja
You're not going to attract more traffic to your blog by posting in 2.5+ year old forum threads.