Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Find maximum working time [Urgent]

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Find maximum working time [Urgent]

    I got a problem.

    Assume i got 4 time interval in figure4 List.

    List<Interval> figure4 = new ArrayList<Interval>();
    figure4.add(new Interval("06:00", "08:30"));
    figure4.add(new Interval("08:00", "10:30"));
    figure4.add(new Interval("10:00", "12:00"));
    figure4.add(new Interval("11:30", "15:00"));

    how to i get the maximum working time without overlapping other interval ?
    By using algorithm


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Find maximum working time [Urgent]

    Please don't post duplicate topics: Duplicate.

    What have you tried?

    Marking something "Urgent" doesn't really help and might even hurt. Sane, intelligent people are typically not interested in becoming embroiled in other people's crises.

    I suggest you simplify the problem to combine intervals that may overlap using integers, then maybe increase the complexity to doubles (with decimals) and then expand that to a different numbering system, like TIME. You'll discover new challenges and learn how to overcome them with each step.

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Find maximum working time [Urgent]

    I've deleted your duplicate post.

    I suggest you take everything Greg just told you seriously.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Junior Member
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Find maximum working time [Urgent]

    Sorry about putting Urgent

    I have done the function to determine maximum interval overlap.
    And the total minute for each interval also can be count.


    if countOverlap return 1 mean no overlap
    if return 2 mean maximum 2 interval are overlap from the List Interval.
    if return 3 mean maximum 3 interval are overlap from the List Interval in a period.


    Code:
    List<Interval> figure4 = new ArrayList<Interval>();
    figure4.add(new Interval("06:00", "08:30")); //150 minute
    figure4.add(new Interval("08:00", "10:30")); //150 minute
    figure4.add(new Interval("07:30", "08:30")); //60 minute
    int countOverlap = getMaxIntervalOverlapCount(figure4);

    Answer: 3


    public static int getMaxIntervalOverlapCount(List<Interval> intervals) {
    int returnValue;
    int big;
    int tempBig;
    int count;
    List<Interval> list1;
    returnValue = 0;
    big = 0;
    tempBig = 0;

    for(int x = 0; x < intervals.size(); x = x+1) {
    int b1 = intervals.get(x).getBeginMinuteUnit();
    int e1 = intervals.get(x).getEndMinuteUnit();
    for (int y = 0; y < intervals.size();y = y + 1){
    if(x != y){
    int b2 = intervals.get(y).getBeginMinuteUnit();
    int e2 = intervals.get(y).getEndMinuteUnit();
    if ((b1 <b2 && b2<e1) ||(b1 <e2 && e2<e1) ){
    int fromTime = 0;
    int toTime = 0;
    if (b1 <= b2){
    fromTime = b2;
    }else{
    fromTime = b1;
    }
    if (e1 <= e2){
    toTime = e1;
    }else{
    toTime = e2;
    }

    count = calculate(intervals,fromTime,toTime);
    if (returnValue < count){
    returnValue = count;
    }
    }
    }
    }
    }
    returnValue = returnValue;
    return returnValue;
    }

    public static int calculate(List<Interval> intervals,int fromTime,int toTime){
    int value;
    value = 0;
    for(int x = 0; x < intervals.size(); x = x+1) {
    int b1 = intervals.get(x).getBeginMinuteUnit();
    int e1 = intervals.get(x).getEndMinuteUnit();
    if (b1 <= fromTime && toTime <= e1){
    value = value + 1;
    }

    }

    return value;
    }



    Now i am thinking
    assume i got 6 interval in List
    how to i get the maximum working time without overlapping each other.

    Previously i have declare 2 dimension array
    int [][] overlap = new int[][];
    if overlap[i][j] > 1
    mean there is overlap between interval i and interval j

    now i am no idea, how to get the logic for calculate maximum working time

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Find maximum working time [Urgent]

    Please post your code in code tags.

    I see you've already made some progress, but not in the crawl, walk, run fashion I suggested. Since you started to work the solution by running rather than thoughtfully crawling, you may be running around in directions that aren't especially helpful. For example, I don't know that the method getMaxIntervalOverlapCount() is particularly useful, at least I don't see its value to deriving a solution.

    I visualize the problem as a number of line segments laid on a number line, some overlap, some don't. There are then a number of useful methods I'd write to characterize the data set that includes those line segments from the min and max times in which they exist: one that adds the length of the line segment regardless of overlap; another that calculates the total overlap; and another that calculates the total time when no work is being done; etc. Once the data set has been adequately characterized, I could then answer any question about the data set anyone could ask.

    You need to visualize the data in some useful way and then characterize it as needed to answer your question(s).

Similar Threads

  1. My Code is not working [URGENT] Help Needed
    By abhijit@92 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 25th, 2012, 04:37 PM
  2. execute a method over a maximum period of time
    By PedroCosta in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 24th, 2011, 02:06 PM
  3. Urgent - File exist nor working
    By Bagzli in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 2nd, 2011, 04:09 AM
  4. Java program to find the minimum and maximum values of input data
    By awake77 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: December 20th, 2008, 05:12 PM