# Thread: Need help with weighted interval scheduling problem.

1. Member
Join Date
Apr 2011
Posts
18
Rep Power
0

## Need help with weighted interval scheduling problem.

This is what I have for my program so far.
Java 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.

2. ## 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

3. Member
Join Date
Nov 2013
Posts
1
Rep Power
0

## 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

4. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

## Re: Need help with weighted interval scheduling problem.

Originally Posted by kartikkukreja
I've written an explanation of the problem, its complexity analysis and provided C++ code here: Weighted Interval Scheduling Problem | Everything Under The Sun
You're not going to attract more traffic to your blog by posting in 2.5+ year old forum threads.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•