action->getMaxDuration());
if (min != -1) {
- action->heapRemove(p_actionHeap);
- action->heapInsert(p_actionHeap, min, max_dur_flag ? MAX_DURATION : NORMAL);
+ action->heapUpdate(p_actionHeap, min, max_dur_flag ? MAX_DURATION : NORMAL);
XBT_DEBUG("Insert at heap action(%p) min %f now %f", action, min,
now);
} else DIE_IMPOSSIBLE;
}
}
+void Action::heapUpdate(xbt_heap_t heap, double key, enum heap_action_type hat)
+{
+ m_hat = hat;
+ if (m_indexHeap >= 0) {
+ xbt_heap_update(heap, m_indexHeap, key);
+ }else{
+ xbt_heap_push(heap, this, key);
+ }
+}
+
/* added to manage the communication action's heap */
void surf_action_lmm_update_index_heap(void *action, int i) {
((ActionPtr)action)->updateIndexHeap(i);
virtual void updateRemainingLazy(double now);
void heapInsert(xbt_heap_t heap, double key, enum heap_action_type hat);
void heapRemove(xbt_heap_t heap);
+ void heapUpdate(xbt_heap_t heap, double key, enum heap_action_type hat);
void updateIndexHeap(int i);
lmm_variable_t getVariable() {return p_variable;}
double getLastUpdate() {return m_lastUpdate;}
#include <stdio.h>
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_heap, xbt, "Heap");
-static void xbt_heap_max_heapify(xbt_heap_t H);
+static void xbt_heap_max_heapify(xbt_heap_t H, int i);
static void xbt_heap_increase_key(xbt_heap_t H, int i);
/** @addtogroup XBT_heap
return;
}
+
/**
* @brief Extracts from the heap and returns the element with the smallest key.
* \param H the heap we're working on
items[0] = items[(H->count) - 1];
(H->count)--;
- xbt_heap_max_heapify(H);
+ xbt_heap_max_heapify(H,0);
if (H->count < size >> 2 && size > 16) {
size = (size >> 1) + 1;
H->items =
return xbt_heap_pop(H);
}
+/**
+ * @brief Updates an element of the heap with a new value.
+ * \param H the heap we're working on
+ * \param i element position
+ * \param key new value for the element
+ *
+ * Updates an element of the heap with a new value.
+ */
+void xbt_heap_update(xbt_heap_t H, int i, double key)
+{
+ XBT_DEBUG("Heap has %d elements: updating element %d : was %1.12f to %1.12f ",xbt_heap_size(H),i,KEY(H, i), key);
+
+ if ((i < 0) || (i > H->count - 1) || key == KEY(H, i))
+ return ;
+
+ if(key< KEY(H, i)){
+ KEY(H, i)=key;
+ xbt_heap_increase_key(H, i);
+ }else{
+ KEY(H, i)=key;
+ xbt_heap_max_heapify(H,i);
+ }
+}
+
/**
* @brief returns the smallest key in the heap (heap unchanged)
* \param H the heap we're working on
*
* Restores the heap property once an element has been deleted.
*/
-static void xbt_heap_max_heapify(xbt_heap_t H)
+static void xbt_heap_max_heapify(xbt_heap_t H, int index)
{
- int i = 0;
+ int i = index;
int count = H->count;
xbt_heap_item_t items = H->items;