|
From: <mar...@us...> - 2008-02-11 02:35:44
|
Revision: 95
http://gridsim.svn.sourceforge.net/gridsim/?rev=95&view=rev
Author: marcos_dias
Date: 2008-02-10 18:35:48 -0800 (Sun, 10 Feb 2008)
Log Message:
-----------
Bug fix in the method that collects information regarding the resources available at a given time. Repeated entries could be included in the resulting list.
Modified Paths:
--------------
branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java
branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java
branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java
Modified: branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2008-02-10 07:09:51 UTC (rev 94)
+++ branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2008-02-11 02:35:48 UTC (rev 95)
@@ -147,7 +147,7 @@
private static final int WINDOW_HEIGHT = 350;
private static final int SHIFT_X = 30;
private static final int SHIFT_Y = 25;
- private static final int SHIFT_BOTTOM = 15;
+ private static final int SHIFT_BOTTOM = 25;
private static final float PROPORTION_LEFT_PANEL = 0.6f;
private static final float PROPORTION_RIGHT_PANEL = 1f - PROPORTION_LEFT_PANEL;
private static final int HEIGHT_COLOR_PANEL = 90;
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2008-02-10 07:09:51 UTC (rev 94)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2008-02-11 02:35:48 UTC (rev 95)
@@ -1804,15 +1804,12 @@
// a pointer to the last entry analysed (described above)
AvailabilityProfileEntry tailEntry = null;
- // the list of selected ranges
- PERangeList intersectList = null;
-
// NOTE: freePERanges_ does not need to be cloned here as the
// PERangeList.intersection() and selectPERangeList() methods will
// create a new list of ranges with the intersection anyway.
// For immediate gridlets or advance reservations, the start point
// is the current list of PEs available
- intersectList = resource_.getFreePERanges();
+ PERangeList intersectList = resource_.getFreePERanges();
// if time is unknown, then make the current time the start time
if(startTime < 0)
@@ -1834,7 +1831,6 @@
}
else {
tailEntry = entry;
- // Sep. 29, 2007 - Changed by Marcos
// if the finish time is equals to the entry time, so there
// is no need to check the intersection
if(entryTime < finishTime) {
@@ -1903,21 +1899,23 @@
while(iterProfile.hasNext()) {
AvailabilityProfileEntry entry = iterProfile.next();
- anchorEntry = entry;
- anchorIndex = availProfile_.indexOf(anchorEntry);
- tailEntry = entry;
-
- // sets the start time as the time of the entry
- potStartTime = entry.getTime();
- // calculates when the finish time will be if
- // the gridlet is put at this position
- potFinishTime = potStartTime + duration;
// scan the profile until an entry with enough PEs is found
if(entry.getNumPE() < reqPE) {
continue;
}
else {
+
+ anchorEntry = entry;
+ anchorIndex = availProfile_.indexOf(anchorEntry);
+ tailEntry = entry;
+
+ // sets the start time as the time of the entry
+ potStartTime = entry.getTime();
+ // calculates when the finish time will be if
+ // the gridlet is put at this position
+ potFinishTime = potStartTime + duration;
+
// if an entry with enough PEs is found, then scan the profile
// from that point onwards analysing the intersection of
// the ranges available in the entries until the
@@ -2016,8 +2014,7 @@
// the list of selected ranges
PERangeList intersectList = null;
-
- intersectList = null;
+
int length = availProfile_.size();
anchorEntry = tailEntry = availProfile_.getPrecedingEntry(startTime);
@@ -2137,9 +2134,9 @@
// Update entries of the profile
for(int index=0; index<tailIndex; index++) {
AvailabilityProfileEntry entry = availProfile_.get(index);
- if(entry.getTime() < startTime){
- continue;
- }
+// if(entry.getTime() < startTime){
+// continue;
+// }
PERangeList uptList =
PERangeList.difference(entry.getPERanges(), selected);
entry.setPERangeList(uptList);
@@ -2186,27 +2183,44 @@
// entries in the availability profile.
boolean addEntryAfterAnchor = false;
- int updFrom = anchorIndex;
- int updTo = tailIndex;
- int anchorInsertPos = anchorIndex;
- int tailInsertPos = tailIndex;
+ if (tailIndex > -1) {
+ AvailabilityProfileEntry tailEntry = availProfile_.get(tailIndex);
+
+ if (tailEntry.getTime() == finishTime) {
+ addEntryAfterTail = false;
+ tailEntry.increaseGridlet();
+ }
+ // If a new entry is required, then created it to be added
+ // to the profile
+ else {
+ // Creates a new entry to be added to the profile
+ newEntryAfterTail = new AvailabilityProfileEntry(finishTime);
+ newEntryAfterTail.setPERangeList(tailEntry.getPERanges().clone());
+ tailIndex++;
+ }
+ }
+ else {
+ // Creates a new entry to be added to the profile
+ newEntryAfterTail = new AvailabilityProfileEntry(finishTime);
+ newEntryAfterTail.setPERangeList(resource_.getFreePERanges().clone());
+ tailIndex++;
+ }
+
+ if(addEntryAfterTail) {
+ availProfile_.add(tailIndex, newEntryAfterTail);
+ }
if (anchorIndex > -1) {
- AvailabilityProfileEntry anchorEntry =
- availProfile_.get(anchorIndex);
+ AvailabilityProfileEntry anchorEntry = availProfile_.get(anchorIndex);
double anchorTime = anchorEntry.getTime();
if ( anchorTime < startTime ) {
addEntryAfterAnchor = true;
- updFrom++;
// Creates a new entry to be added to the profile
newEntryAfterAnchor = new AvailabilityProfileEntry(startTime);
- PERangeList difference =
- PERangeList.difference(anchorEntry.getPERanges(), selected);
- newEntryAfterAnchor.setPERangeList(difference);
- // increment the tail index as a new anchor will be
- // inserted before the new tail entry
- tailInsertPos++;
+ newEntryAfterAnchor.setPERangeList(anchorEntry.getPERanges().clone());
+ // increment the position where the new anchor will be added
+ anchorIndex++;
}
else if (anchorTime == startTime) {
anchorEntry.increaseGridlet();
@@ -2217,58 +2231,25 @@
// Creates a new entry to be added to the profile
newEntryAfterAnchor = new AvailabilityProfileEntry(startTime);
- PERangeList difference =
- PERangeList.difference(resource_.getFreePERanges(), selected);
- newEntryAfterAnchor.setPERangeList(difference);
- // increment the tail index as a new anchor will be
- // inserted before the new tail entry
- tailInsertPos++;
- updFrom++;
+ newEntryAfterAnchor.setPERangeList(resource_.getFreePERanges().clone());
+ // increment the position where the new anchor will be added
+ anchorIndex++;
}
- if (tailIndex > -1) {
- AvailabilityProfileEntry tailEntry =
- availProfile_.get(tailIndex);
-
- if (tailEntry.getTime() == finishTime) {
- addEntryAfterTail = false;
- updTo--;
- tailEntry.increaseGridlet();
- }
- // If a new entry is required, then created it to be added
- // to the profile
- else {
- // Creates a new entry to be added to the profile
- newEntryAfterTail = new AvailabilityProfileEntry(finishTime);
- newEntryAfterTail.setPERangeList(tailEntry.getPERanges().clone());
- }
- }
- else {
- // Creates a new entry to be added to the profile
- newEntryAfterTail = new AvailabilityProfileEntry(finishTime);
- newEntryAfterTail.setPERangeList(resource_.getFreePERanges().clone());
- }
-
+ if(addEntryAfterAnchor) {
+ availProfile_.add(anchorIndex, newEntryAfterAnchor);
+ tailIndex++;
+ }
+
// Update entries of the profile
if(tailIndex > -1) {
- for(int index=updFrom; index<=updTo; index++){
+ for(int index=anchorIndex; index<tailIndex; index++){
AvailabilityProfileEntry entry = availProfile_.get(index);
PERangeList uptList =
PERangeList.difference(entry.getPERanges(), selected);
entry.setPERangeList(uptList);
}
}
-
- anchorInsertPos++;
- tailInsertPos++;
-
- if(addEntryAfterAnchor) {
- availProfile_.add(anchorInsertPos, newEntryAfterAnchor);
- }
-
- if(addEntryAfterTail) {
- availProfile_.add(tailInsertPos, newEntryAfterTail);
- }
}
/**
@@ -2283,15 +2264,16 @@
* specified by the requester.
*/
protected AvailabilityInfo getAvailabilityInfo(double startTime, int duration) {
-
+
AvailabilityInfo list = new AvailabilityInfo();
int anchorIndex = -1;
+ double currentTime = GridSim.clock();
// if the user specified the start time as 0, it means that the
// user is interested to know the availability starting from the
// current time, or the time when the resource received this request
if(startTime == 0) {
- startTime = GridSim.clock();
+ startTime = currentTime;
}
list.setStartTime(startTime);
@@ -2305,48 +2287,51 @@
int length = availProfile_.size();
AvailabilityInfoEntry firstEntry = null;
- anchorEntry = availProfile_.getPrecedingEntry(startTime);
+ anchorEntry = (startTime <= currentTime) ? null :
+ availProfile_.getPrecedingEntry(startTime);
// if the entry is null, then it means that the reservation is
// before the first entry of the profile, so the intersection list
// has to start with the ranges of PEs currently available
if (anchorEntry == null) {
- PERangeList peList = (resource_.getFreePERanges() == null) ? null :
- resource_.getFreePERanges().clone();
+ PERangeList peList = (resource_.getFreePERanges() == null) ?
+ new PERangeList() : resource_.getFreePERanges().clone();
firstEntry =
new AvailabilityInfoEntry(startTime, peList);
}
else {
PERangeList newList = anchorEntry.getPERanges();
- if(newList != null) {
- newList = newList.clone();
- }
- firstEntry = new AvailabilityInfoEntry(startTime, newList);
+ newList = (newList != null) ? newList.clone() : new PERangeList();
+ firstEntry = new AvailabilityInfoEntry(startTime, newList);
anchorIndex = availProfile_.indexOf(anchorEntry);
}
list.add(firstEntry);
+ AvailabilityInfoEntry previousEntry = firstEntry;
// Iterates the availability profile and adds all the entries
// whose times are between start and finish time in the list
- // to be returned.
+ // to be returned. It removes repeated entries.
for(int i=anchorIndex+1; i<length; i++) {
AvailabilityProfileEntry nextEntry = availProfile_.get(i);
+ if(nextEntry.getTime() <= startTime)
+ continue;
if(nextEntry.getTime() > finishTime){
break;
}
else {
PERangeList peList = nextEntry.getPERanges();
- if(peList != null) {
- peList = peList.clone();
+ peList = (peList != null) ? peList.clone() : new PERangeList();
+
+ if( !previousEntry.getAvailRanges().equals(peList)) {
+ AvailabilityInfoEntry tsEntry =
+ new AvailabilityInfoEntry(nextEntry.getTime(), peList);
+ list.add(tsEntry);
+ previousEntry = tsEntry;
}
- AvailabilityInfoEntry tsEntry =
- new AvailabilityInfoEntry(nextEntry.getTime(), peList);
- list.add(tsEntry);
}
}
-
- list.sort(); // sort the list before send it back
+
return list;
}
}
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java 2008-02-10 07:09:51 UTC (rev 94)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java 2008-02-11 02:35:48 UTC (rev 95)
@@ -107,23 +107,6 @@
}
/**
- * Returns <tt>true</tt> if this entry has the same list of ranges of PEs
- * as the entry provided.
- * @param entry the entry whose ranges have to be compared
- * @return <tt>true</tt> if the ranges are the same or false otherwise.
- */
- public boolean hasSamePERanges(AvailabilityProfileEntry entry) {
- boolean result = false;
- if(ranges_ == null && entry.ranges_ == null) {
- result = true;
- }
- else if(ranges_ != null) {
- result = ranges_.equals(entry.ranges_);
- }
- return result;
- }
-
- /**
* Creates a string representation of this entry
*/
public String toString(){
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|