Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By gimbal2

Thread: Need help with weighted interval scheduling problem.

  1. #1
    chris1 is offline Member
    Join Date
    Apr 2011
    Posts
    18
    Rep Power
    0

    Default 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. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,679
    Blog Entries
    7
    Rep Power
    21

    Default 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
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    kartikkukreja is offline Member
    Join Date
    Nov 2013
    Posts
    1
    Rep Power
    0

    Default 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. #4
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,161
    Rep Power
    6

    Default Re: Need help with weighted interval scheduling problem.

    Quote Originally Posted by kartikkukreja View Post
    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.
    jim829 likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Generate weighted random numbers, nextGaussian ()
    By graympa in forum New To Java
    Replies: 2
    Last Post: 03-25-2011, 10:36 PM
  2. Scheduling problem with FCFS/FIFO
    By ShutUpAndExplode in forum New To Java
    Replies: 7
    Last Post: 04-26-2010, 06:45 PM
  3. weighted GPA
    By cheekee.monkee in forum New To Java
    Replies: 3
    Last Post: 12-03-2009, 08:01 PM
  4. need info on running thread during a particular time interval alone
    By karthikeyan_raju in forum Threads and Synchronization
    Replies: 2
    Last Post: 10-06-2009, 03:40 AM
  5. Scheduling a task
    By bugger in forum Advanced Java
    Replies: 3
    Last Post: 12-04-2007, 01:32 PM

Posting Permissions

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