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

# Thread: Find maximum working time [Urgent]

1. ## Find maximum working time [Urgent]

I got a problem.

Assume i got 4 time interval in figure4 List.

List<Interval> figure4 = new ArrayList<Interval>();

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

2. ## 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. ## Re: Find maximum working time [Urgent]

I suggest you take everything Greg just told you seriously.

4. ## Re: Find maximum working time [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>();
int countOverlap = getMaxIntervalOverlapCount(figure4);

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