Ejemplo n.º 1
0
float waitingTimeSJF(int* requestTimes, int *durations, int n) {
	int cur = 0, wait = 0, i = 0;
	priority_queue<task, vector<task>, cmp> pq;
	while (!pq.empty() || i < n) {
		if (!pq.empty()) {
			task t = pq.top();
			pq.pop();
			wait += (cur - t.arrive);
			cur += t.execute;
			for (; i < n; i++) {
				if (requestTimes[i] <= cur) {
					task newT(requestTimes[i], durations[i]);
					pq.push(newT);
				}
				else {
					break;
				}
			}
		}
		else {
			task newT(requestTimes[i], durations[i]);
			pq.push(newT);
			cur = requestTimes[i++];
		}
	}
	return (float)(wait) / n;
}
Ejemplo n.º 2
0
void deleteZeroTriangles(Mesh& m) {
  uintA newT;
  newT.resizeAs(m.T);
  uint i, j;
  for(i=0, j=0; i<m.T.d0; i++) {
    if(m.T(i, 0)!=m.T(i, 1) && m.T(i, 0)!=m.T(i, 2) && m.T(i, 1)!=m.T(i, 2))
      memmove(&newT(j++, 0), &m.T(i, 0), 3*newT.sizeT);
  }
  newT.resizeCopy(j, 3);
  m.T=newT;
}
Ejemplo n.º 3
0
void Mesh::subDevide() {
  uint v=V.d0, t=T.d0;
  V.resizeCopy(v+3*t, 3);
  uintA newT(4*t, 3);
  uint a, b, c, i, k, l;
  for(i=0, k=v, l=0; i<t; i++) {
    a=T(i, 0); b=T(i, 1); c=T(i, 2);
    V[k+0]() = (double).5*(V[a] + V[b]);
    V[k+1]() = (double).5*(V[b] + V[c]);
    V[k+2]() = (double).5*(V[c] + V[a]);
    newT(l, 0)=a;   newT(l, 1)=k+0; newT(l, 2)=k+2; l++;
    newT(l, 0)=k+0; newT(l, 1)=b;   newT(l, 2)=k+1; l++;
    newT(l, 0)=k+0; newT(l, 1)=k+1; newT(l, 2)=k+2; l++;
    newT(l, 0)=k+2; newT(l, 1)=k+1; newT(l, 2)=c;   l++;
    k+=3;
  }
  T = newT;
}