Beispiel #1
0
// allocates memory
void setup()
{
  int i;
  double sc = 0, sm = 0;
  C = pow(2., L/2.);   // constant
  U = (1ul<<L)-1;      // universe mask
  for (i = 256; i--; W[i] = ((ones(i)&1) ? -1. : 1.)/C);
  // allocate memory and calculate crossover and mutation 
  Chi = calloc((1ul<<L),sizeof(double));
  Mu = calloc((1ul<<L),sizeof(double));
  Cr = allocdist((1ul<<L));
  M = allocdist((1ul<<L));
  initOneCount();
  P0 = malloc((1ul<<L)*sizeof(double));
  P1 = malloc((1ul<<L)*sizeof(double));
  P2 = malloc((1ul<<L)*sizeof(double));
  P3 = malloc((1ul<<L)*sizeof(double));  
  
  chiDist(12); muDist(12);                         // initialize distributions for Mu and Chi with g = 12
  for(i = 0; i < 1ul<<L; i++){                     // copy mutation and crossover distributions to Cr and M distributions
    Cr->p[i] = Chi[i]; sc += Chi[i];
    M->p[i] = Mu[i]; sm += Mu[i];
  }
  initdist(Cr, sc);                                // initialize Cr distribution
  initdist(M, sm);                                 // initialize M distribution
  
  Mh  = malloc((1ul<<L)*sizeof(double *));
  for (i = 1ul<<L; i--;) Mh[i]  = malloc((1ul<<L)*sizeof(double));
  walsh(Mh);                                       // calculate and install values in mixing matrix in walsh basis (Mhat)
  GZ = malloc((1ul<<L)*sizeof(double));
  GW = malloc((1ul<<L)*sizeof(double)); 
   
}
Beispiel #2
0
// returns index of randomly chosen event with probability associated with event
int select_event()
{
  int j;
  double sum;  
  for(sum = 0.0, j = 0; j < EVENTS; j++){
    Event_dist->p[j] = PE[j];
    sum += PE[j];
  }
  initdist(Event_dist, sum);         // initialise distribution event_dist
  
  return drand(Event_dist);          // selects one event randomly from distribution and returns index  
}
Beispiel #3
0
/** Compute maximum flow using batch relabeling.  */
void mflo_pp::maxFlowBatch() {
	initdist();
	vertex s = g->src();
        for (edge e = g->firstOut(s); e != 0; e = g->nextAt(s,e)) {
		vertex v = g->head(e);
		if (excess[v] > 0) addUnbal(v);
	}
	vertex u = removeUnbal();
     	while (u != 0) {
     		do {
			balance(u);
			u = removeUnbal();
		} while (u != 0);
                initdist();
                for (u = 1; u <= g->n(); u++) {
			if (u == g->src() || u == g->snk()) continue;
                        nextedge[u] = g->firstAt(u);
                        if (excess[u] > 0) addUnbal(u);
                }
		u = removeUnbal();
        }
	return;
}
Beispiel #4
0
/** Helper method that implements the core algorithm common to the two
 *  constructors.
 *  @param batch is a boolean which determines if the algorithm uses
 *  batch relabeling (batch=true) or incremental relabeling (batch=false)
 */
void ppHiLab::doit(bool batch) {
	// ubVec[d] is an unbalanced vertex with a distance label of d
	// or 0 if there is no unbalanced vertex with a distance label of d
	// unbal partitions the vertices into circular lists, where all
	// vertices on the same list are unbalanced and have the same
	// distance label; balanced vertices each form singleton lists
	ubVec = new int[2*fg->n()];
	unbal = new UiClist(fg->n());

	// initialization
	for (int i = 0; i < 2*fg->n(); i++) ubVec[i] = 0;
	top = 0;
	vertex s = fg->src();
        for (edge e = fg->firstOut(s); e != 0; e = fg->nextOut(s,e)) {
                vertex v = fg->head(e);
                if (v != fg->snk()) addUnbal(v);
        }

	vertex u, v;
	if (!batch) { // incremental relabeling
     		while (top > 0) {
			u = removeUnbal();
			if (!balance(u)) {
				d[u] = 1 + minlabel(u);
				nextedge[u] = fg->firstAt(u);
				addUnbal(u);
				relabCount++;
			}
		}
	} else { // batch relabeling
	     	while (top > 0) {
	     		while (top > 0) {
				u = removeUnbal();
				balance(u);
			}
	                initdist();
	                for (u = 1; u <= fg->n(); u++) {
				if (u == fg->src() || u == fg->snk()) continue;
	                        nextedge[u] = fg->firstAt(u);
	                        if (excess[u] > 0) addUnbal(u);
	                }
	        }
	}
	delete unbal; delete [] ubVec;
}
Beispiel #5
0
/** Compute maximum flow using incremental relabeling.  */
void mflo_pp::maxFlowIncr() {
	initdist();
	vertex s = g->src();
        for (edge e = g->firstOut(s); e != 0; e = g->nextAt(s,e)) {
		vertex v = g->head(e);
		if (excess[v] > 0) addUnbal(v);
	}
	vertex u = removeUnbal();
	while (u != 0) {
		if (!balance(u)) {
			d[u] = 1 + minlabel(u);
			nextedge[u] = g->firstAt(u);
			addUnbal(u);
		}
		u = removeUnbal();
	}
	return;
}
Beispiel #6
0
prePush::prePush(Flograph& fg1, int& floVal) : fg(&fg1) {
// Find maximum flow in fg using the preflow-push method.
// The base clase constructor initializes data used by all
// variants.

	excess = new int[fg->n()+1];
	nextedge = new edge[fg->n()+1];

	// initialization
	for (vertex u = 1; u <= fg->n(); u++) {
		nextedge[u] = fg->firstAt(u); excess[u] = 0;
	}
	vertex s = fg->src();
        for (edge e = fg->firstOut(s); e != 0; e = fg->nextAt(s,e)) {
                vertex v = fg->head(e);
                fg->addFlow(s,e,fg->cap(s,e));
                if (v != fg->snk()) excess[v] = fg->cap(s,e);
        }
	d = new int[fg->n()+1];
	satCount = nonSatCount = newDistCount = relabCount = 0;
	initdist();
	// constructor of derived class takes over from here
}
Beispiel #7
0
static inline void exp_initdist(dist *d, double m) // m = max d->p[i]
{
  int i = d->n;  double s = 0;
  while(i--) s += (d->p[i] = exp(d->p[i] - m));
  initdist(d,s);
}