Esempio n. 1
0
sPopulation * createPopulation(int nbIn, int nbOut, sParams * params) {
  int i;
  sPopulation * pop = malloc(sizeof(*pop));
  // genomes
  pop->iNumGenomes = params->iNumIndividuals;
  pop->iNextGenomeId = 0;
  pop->vGenomes = calloc(pop->iNumGenomes, sizeof(*pop->vGenomes));
  //create the population of genomes
  for (i = 0; i < params->iNumIndividuals; i++) {
    pop->vGenomes[i] = createInitialGenome(pop->iNextGenomeId++, nbIn, nbOut);
    // DUMP GENOMES
    if (UltraVerbose) dumpGenome(stdout, pop->vGenomes[i]);
  }
  // the species
  pop->iTotalSpecies = INIT_VECT_SIZE;
  pop->vSpecies = calloc(pop->iTotalSpecies, sizeof(*pop->vSpecies));
  pop->iNumSpecies = 0;
  pop->iNextSpeciesId = 0;
  // to keep track of innovations (take the first genome as model)
  pop->sInnovTable = createNewInnovTable(pop->vGenomes[0]->vNeurons,
                                        pop->vGenomes[0]->iNumNeurons,
                                        pop->vGenomes[0]->vLinks,
                                        pop->vGenomes[0]->iNumLinks);
  // DUMP INNOVATION TABLE
  if (UltraVerbose) dumpInnovTable(stdout, pop->sInnovTable);
  //current generation
  pop->iGeneration = 1;
  //adjusted fitness scores
  pop->dTotFitAdj = 0;
  pop->dAvFitAdj = 0;
  //index into the genomes for the fittest genome
  pop->iFittestGenome = 0;
  pop->dBestEverFitness = 0;
  pop->sParams = params;
  // depth lookup table
  pop->iTotalDepths = INIT_VECT_SIZE;
  pop->vDepths = calloc(pop->iTotalDepths, sizeof(*pop->vDepths));
  pop->iNumDepth = 0;
  addDepth(pop, 0);
  addDepth(pop, 1);
  return pop;
}
Esempio n. 2
0
void writePlaintextParagraph(Buffer const & buf,
                             Paragraph const & par,
                             odocstream & os,
                             OutputParams const & runparams,
                             bool & ref_printed)
{
    int ltype = 0;
    depth_type ltype_depth = 0;
    depth_type depth = par.params().depth();

    // First write the layout
    string const tmp = to_utf8(par.layout().name());
    if (compare_ascii_no_case(tmp, "itemize") == 0) {
        ltype = 1;
        ltype_depth = depth + 1;
    } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
        ltype = 2;
        ltype_depth = depth + 1;
    } else if (contains(ascii_lowercase(tmp), "ection")) {
        ltype = 3;
        ltype_depth = depth + 1;
    } else if (contains(ascii_lowercase(tmp), "aragraph")) {
        ltype = 4;
        ltype_depth = depth + 1;
    } else if (compare_ascii_no_case(tmp, "description") == 0) {
        ltype = 5;
        ltype_depth = depth + 1;
    } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
        ltype = 6;
        ltype_depth = 0;
    } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
        ltype = 7;
        ltype_depth = 0;
    } else {
        ltype = 0;
        ltype_depth = 0;
    }

    /* the labelwidthstring used in lists */

    /* noindent ? */

    /* what about the alignment */

    // runparams.linelen == 0 is special and means we don't have paragraph breaks

    string::size_type currlinelen = 0;

    os << docstring(depth * 2, ' ');
    currlinelen += depth * 2;

    //--
    // we should probably change to the paragraph language in the
    // support/gettext.here (if possible) so that strings are output in
    // the correct language! (20012712 Jug)
    //--
    switch (ltype) {
    case 0: // Standard
    case 4: // (Sub)Paragraph
    case 5: // Description
        break;

    case 6: // Abstract
        if (runparams.linelen > 0) {
            os << buf.B_("Abstract") << "\n\n";
            currlinelen = 0;
        } else {
            docstring const abst = buf.B_("Abstract: ");
            os << abst;
            currlinelen += abst.length();
        }
        break;

    case 7: // Bibliography
        if (!ref_printed) {
            if (runparams.linelen > 0) {
                os << buf.B_("References") << "\n\n";
                currlinelen = 0;
            } else {
                docstring const refs = buf.B_("References: ");
                os << refs;
                currlinelen += refs.length();
            }
            ref_printed = true;
        }
        break;

    default: {
        docstring const label = par.params().labelString();
        if (!label.empty()) {
            os << label << ' ';
            currlinelen += label.length() + 1;
        }
        break;
    }

    }

    if (currlinelen == 0) {
        pair<int, docstring> p = addDepth(depth, ltype_depth);
        os << p.second;
        currlinelen += p.first;
    }

    docstring word;

    for (pos_type i = 0; i < par.size(); ++i) {
        // deleted characters don't make much sense in plain text output
        if (par.isDeleted(i))
            continue;

        char_type c = par.getUChar(buf.params(), i);

        if (par.isInset(i) || c == ' ') {
            if (runparams.linelen > 0 &&
                    currlinelen + word.length() > runparams.linelen) {
                os << '\n';
                pair<int, docstring> p = addDepth(depth, ltype_depth);
                os << p.second;
                currlinelen = p.first;
            }
            os << word;
            currlinelen += word.length();
            word.erase();
        }

        if (par.isInset(i)) {
            OutputParams rp = runparams;
            rp.depth = par.params().depth();
            int len = par.getInset(i)->plaintext(os, rp);
            if (len >= Inset::PLAINTEXT_NEWLINE)
                currlinelen = len - Inset::PLAINTEXT_NEWLINE;
            else
                currlinelen += len;
            continue;
        }

        switch (c) {
        case ' ':
            os << ' ';
            currlinelen++;
            break;

        case '\0':
            LYXERR(Debug::INFO, "writePlaintextFile: NUL char in structure.");
            break;

        default:
            word += c;
            break;
        }
    }

    // currlinelen may be greater than runparams.linelen!
    // => check whether word is empty and do nothing in this case
    if (!word.empty()) {
        if (runparams.linelen > 0 &&
                currlinelen + word.length() > runparams.linelen) {
            os << '\n';
            pair<int, docstring> p = addDepth(depth, ltype_depth);
            os << p.second;
            currlinelen = p.first;
        }
        os << word;
    }
}
Esempio n. 3
0
void BlockBccMeshBuilder::build(AOrientedBox * ob)
{
	int gx = ob->extent().x * 2.f / EstimatedGroupSize;
	if(gx > MaximumUGrid ) gx = MaximumUGrid;
	else if(gx < MinimumUGrid ) gx = MinimumUGrid;
	
	int gy = ob->extent().y * 2.f / EstimatedGroupSize;
	if(gy > MaximumVGrid ) gy = MaximumVGrid;
	else if(gy < MinimumVGrid ) gy = MinimumVGrid;
	
	int gz = ob->extent().z * 2.f / EstimatedGroupSize;
	if(gz > MaximumWGrid ) gz = MaximumWGrid;
	else if(gz < MinimumWGrid ) gz = MinimumWGrid;
	
    const Vector3F center = ob->center();
    const float span = ob->extent().x;
    float originSpan[4];
    originSpan[0] = center.x - span * 1.01f;
    originSpan[1] = center.y - span * 1.01f;
    originSpan[2] = center.z - span * 1.01f;
    originSpan[3] = span * 2.0202f;
    m_verticesPool->setBounding(originSpan);
    const float cellSize = span * 2.f / (float)gx;
    const float cellSizeH = cellSize * .5f;
    
    const Vector3F cellOrigin(center.x - cellSize * (float)gx * .5f + cellSizeH,
                        center.y - cellSize * (float)gy * .5f + cellSizeH,
                        center.z - cellSize * (float)gz * .5f + cellSizeH);
    Vector3F cellCenter;
    int i, j, k;
    for(k=0;k<gz;k++) {
        cellCenter.z = cellOrigin.z + cellSize * k;
        for(j=0;j<gy;j++) {
            cellCenter.y = cellOrigin.y + cellSize * j;
            for(i=0;i<gx;i++) {
                cellCenter.x = cellOrigin.x + cellSize * i;
				addNorth(cellCenter, cellSize, cellSizeH);
            }
        }
    }
	
	const Vector3F staggerOrigin = cellOrigin + Vector3F::XAxis * cellSizeH
									- Vector3F::YAxis * cellSizeH;
	
	for(k=0;k<gz;k++) {
        cellCenter.z = staggerOrigin.z + cellSize * k;
        for(j=0;j<gy+1;j++) {
            cellCenter.y = staggerOrigin.y + cellSize * j;
            for(i=0;i<gx-1;i++) {
                cellCenter.x = staggerOrigin.x + cellSize * i;
				addEast(cellCenter, cellSize, cellSizeH, j, gy);
            }
        }
    }
	
	if(gz>1) {
		const Vector3F fillOrigin = cellOrigin - Vector3F::YAxis * cellSizeH
									+ Vector3F::ZAxis * cellSizeH;
	
		for(k=0;k<gz-1;k++) {
			cellCenter.z = fillOrigin.z + cellSize * k;
			for(j=0;j<gy+1;j++) {
				cellCenter.y = fillOrigin.y + cellSize * j;
				for(i=0;i<gx;i++) {
					cellCenter.x = fillOrigin.x + cellSize * i;
					addDepth(cellCenter, cellSize, cellSizeH, j, gy);
				}
			}
		}
	}

// convert to index
	unsigned c = pointDrifts.back();
	sdb::CellHash * nodes = m_verticesPool->cells();
	nodes->begin();
	while(!nodes->end()) {
		nodes->value()->index = c;
		c++;
		nodes->next();
	}
	
	std::vector<unsigned >::iterator it = tetrahedronInd.begin();
	it += indexDrifts.back();
	for(;it!=tetrahedronInd.end();++it) {
		sdb::CellValue * found = m_verticesPool->findCell(*it);
		if(found) *it = found->index;
		else std::cout<<"\n error cannot find node "<<*it;
	}
	
// add p in world space
	Vector3F q;
	nodes->begin();
	while(!nodes->end()) {
		q = m_verticesPool->cellCenter(nodes->key());
		q -= ob->center();
		q = ob->orientation().transform(q);
		q += ob->center();
		tetrahedronP.push_back(q);
		nodes->next();
	}
}
void Synth_Class::softKill(int steps){
  addDepth(_dutyCycle,steps);
  _dutyCycle=_volatileDuty=0;
  autoKill(steps);
  return;
}
void Synth_Class::note(int pitch, int duty, int depth, int steps){
  noteOn(pitch,duty);
  addDepth(depth,steps);
  return;
}