Exemplo n.º 1
0
void TerrainTile::decode(const int bitset)
{
   reset();

   if (bitset & 0x1)
   {
      setTree(true);
   }
   if (bitset & 0x2)
   {
      setRock(true);
   }
   if (bitset & 0x4)
   {
      setWater(true);
   }
   if (bitset & 0x8)
   {
      setBuilding(true);
   }
   if (bitset & 0x10)
   {
      setTree(true);
   }
   if (bitset & 0x20)
   {
      // setGarden(true);
   }
   if (bitset & 0x40)
   {
      setRoad(true);
   }
   if (bitset & 0x100)
   {
      //setAqueduct(true);
   }
   if (bitset & 0x200)
   {
      //setElevation(true);
   }
   if (bitset & 0x400)
   {
       int i=0;
       setRock( true );
      //setAccessRamp(true);
   }
   if (bitset & 0x800)
   {
      //setMeadow(true);
   }
   if (bitset & 0x4000)
   {
      //setWall(true);
   }
}
int main() {
    int n, x, y, i;
    int cases = 0;
    char op[10], cmd[50];
    while(scanf("%d", &n) == 1 && n) {
        for(M = 1; M < n+2; M <<= 1);
        memset(A, 0, sizeof(A));
        for(i = 1; i <= n; i++)
            scanf("%d", &A[i]);
        while(getchar() != '\n');
        if(cases)   puts("");
        printf("Case %d:\n", ++cases);
        setTree();
        while(gets(cmd)) {
            if(cmd[0] == 'E')
                break;
            sscanf(cmd, "%s %d %d", op, &x, &y);
            if(op[0] == 'M')
                printf("%d\n", query(x, y));
            else {
                singleModify(x, y-A[x]);
                A[x] = y;
            }
        }
    }
    return 0;
}
void CtrlrPanelComponentProperties::changeListenerCallback (ChangeBroadcaster* source)
{
    if (owner.getSelection() == nullptr)
        return;

	if (selectedItems != owner.getSelection()->getNumSelected() && owner.getSelection()->getNumSelected() > 1)
	{
		selectedItems = owner.getSelection()->getNumSelected();
		msTree = ValueTree(Ids::modulator);
		msTree.removeListener (this);

		for (int i=0; i<owner.getSelection()->getNumSelected(); i++)
		{
			ValueTree modTree = owner.getSelection()->getSelectedItem(i)->getOwner().getModulatorTree();

			copyProperties (modTree, msTree);

			for (int i=0; i<modTree.getNumChildren(); i++)
			{
				if (!msTree.getChildWithName(modTree.getChild(i).getType()).isValid())
					msTree.addChild (modTree.getChild(i).createCopy(), i, 0);
			}
		}

		if (msTree.getChildWithName(Ids::component).isValid())
		{
			msTree.getChildWithName(Ids::component).setProperty (Ids::uiType, "uiMultipleSelection", 0);
		}

		msTree.addListener (this);
		setTree (msTree);
	}

	if (owner.getSelection()->getNumSelected() == 0)
	{
		setTree (owner.getOwner().getPanelTree());
		propertyPanel->restoreOpennessState(panelPropertyOpennessState);
	}

	if (owner.getSelection()->getNumSelected() == 1)
	{
	    refreshTargetModulationPropertyList(owner.getSelection()->getSelectedItem(0)->getOwner().getModulatorTree());
		refreshDynamicData();
		setTree (owner.getSelection()->getSelectedItem(0)->getOwner().getModulatorTree());
		propertyPanel->restoreOpennessState(modulatorPropertyOpennessState);
	}
}
Exemplo n.º 4
0
void setTree(int p,int fa)
{
	h[p]=h[fa]+1;
	le[p]=++timetip;
	for(int i=head[p];i;i=nxt[i])
		if(eg[i]!=fa)
			setTree(eg[i],p);
	ri[p]=timetip;
}
Exemplo n.º 5
0
// compute the cdf given a tree
void pmsBP_C(double *weights, double * grid, int * ngrid, int *maxS, double * out, int *log_p)
{
	struct bintree *w = new struct bintree;
	setTree(1.0, w);
	//struct bintree *w = newtree(1);
	array2tree(weights, maxS[0], w);
	pmsBP(w, out, grid, ngrid, log_p);
	deleteTree(w);
}
Exemplo n.º 6
0
// random sample from a msBP density
void rsample_msBP_C(int *N, double * Rvec, double *Svec, double *a, double *b, int * maxS, double *ans)
{
	int i = 0;	
	struct bintree * Stree = new struct bintree;
	struct bintree * Rtree = new struct bintree;
	setTree(1.0, Stree);
	setTree(1.0, Rtree);
	//struct bintree *Stree = newtree(1);
	//struct bintree *Rtree = newtree(1);
	array2tree(Svec, maxS[0], Stree);
	array2tree(Rvec, maxS[0], Rtree);
	for(i=0; i<N[0]; i++)
	{
		ans[i] = rsample_msBP(Rtree,Stree,a[0],b[0]);
	}
	deleteTree(Rtree);
	deleteTree(Stree);
}
Exemplo n.º 7
0
//compute the posterior cluster allocation with slice sampler [Algorithm 2]
void postCluster_C(int *s, int *h, double *y, double *pi, int *maxS, int *N, int *printscreen)
{
	struct bintree *pitree = new struct bintree;
	setTree(1.0, pitree);
	//struct bintree *pitree = newtree(1);
	array2tree(pi, maxS[0], pitree);
	postCluster(s, h, y, pitree, *maxS, *N, *printscreen);
	deleteTree(pitree);
} 
Exemplo n.º 8
0
// compute the weigths given a tree 
void computeprob_C(double *S, double * R, int *maxS, double *a, double *b, double *ans, int *root)
{
	struct bintree *Stree = new struct bintree;
	struct bintree *Rtree = new struct bintree;
	setTree(1.0, Stree);
	setTree(1.0, Rtree);
///	struct bintree *Stree = newtree(1);
//	struct bintree *Rtree = newtree(1);
//	struct bintree *anstree = newtree(1);
	if(root[0]==0) S[0] = 0;
	array2tree(S, maxS[0], Stree);
	array2tree(R, maxS[0], Rtree);
	struct bintree *anstree = computeprob(Stree, Rtree, a[0], b[0], maxS[0], 1);
	tree2array(anstree, ans, maxS[0], 0);
	deleteTree(Stree);
	deleteTree(Rtree);
	deleteTree(anstree);
} 
Exemplo n.º 9
0
void setTree(int p)
{
	for(int i=head[p],pt;i;i=nxt[i])
		if(eg[i]!=fa[p])
		{
			pt=eg[i];
			fa[pt]=p;
			setTree(pt);
		}
}
Exemplo n.º 10
0
void TerrainTile::decode(const int bitset)
{
  clearFlags();

  if (bitset & 0x1)    {  setTree(true);      }
  if (bitset & 0x2)    {  setRock(true);      }
  if (bitset & 0x4)    {  setWater(true);     }
  if (bitset & 0x8)    {  setBuilding(true);  }
  if (bitset & 0x10)   {  setTree(true);      }
  if (bitset & 0x20)   {  setGarden(true);    }
  if (bitset & 0x40)   {  setRoad(true);      }
  if (bitset & 0x100)  {  setAqueduct(true);  }

  if (bitset & 0x200)  {  setElevation(true); }
  if (bitset & 0x400)  {  setRock( true );    }
  if (bitset & 0x800)  {  setMeadow(true);    }
  if (bitset & 0x4000) {  setWall(true);      }
  if (bitset & 0x8000) {  setGateHouse(true); }
}
Exemplo n.º 11
0
void RateMeyerHaeseler::runIterativeProc(Params &params, IQTree &tree) {
	int i;
	if (verbose_mode >= VB_MED) {
		ofstream out("x");
		out.close();
	}
	setTree(&tree);
	RateHeterogeneity *backup_rate = tree.getRate();
	if (backup_rate->getGammaShape() > 0 ) {
		IntVector pattern_cat;
		backup_rate->computePatternRates(*this, pattern_cat);
		double sum = 0.0;
		for (i = 0; i < size(); i++)
			sum += at(i) * phylo_tree->aln->at(i).frequency;
		sum /=  phylo_tree->aln->getNSite();
		if (fabs(sum - 1.0) > 0.0001) {
			if (verbose_mode >= VB_MED)
				cout << "Normalizing Gamma rates (" << sum << ")" << endl;
			for (i = 0; i < size(); i++)
				at(i) /= sum;
		}
	}
	tree.getModelFactory()->site_rate = this;
	tree.setRate(this);

	
	//if  (empty()) initializeRates();

	//setRates(prev_rates);
	//string rate_file = params.out_prefix;
	//rate_file += ".mhrate";
	double prev_lh = tree.getCurScore();
	string dist_file = params.out_prefix;
	dist_file += ".tdist";
	tree.getModelFactory()->stopStoringTransMatrix();

	for (i = 2; i < 100; i++) {
		//DoubleVector prev_rates;
		//getRates(prev_rates);
		//writeSiteRates(prev_rates, rate_file.c_str());
		tree.setCurScore(optimizeParameters(0.0));
		//phylo_tree->aln->printDist(dist_file.c_str(), dist_mat);
		tree.setCurScore(tree.optimizeAllBranches(i));
		cout << "Current Log-likelihood: " << tree.getCurScore() << endl;
		if (tree.getCurScore() <= prev_lh + 1e-4) {
			break;
		}
		prev_lh = tree.getCurScore();
	}
	cout << "Optimization took " << i-1 << " rounds to finish" << endl;
	tree.getModelFactory()->startStoringTransMatrix();
	//tree.getModelFactory()->site_rate = backup_rate;
	//tree.setRate(backup_rate);
}
Exemplo n.º 12
0
ChangeLengthVariation::ChangeLengthVariation(float ol, float fl, QVector<long> branchesBeingModifiedIden, QVector<float> origVariationLengths,
        QVector<float> finalVariationLengths, QString pt, long id, Branch* tr)
{
    origLength = ol;
    finalLength = fl;
    branchIdentifiers = branchesBeingModifiedIden;
    origLengths = origVariationLengths;
    finalLengths = finalVariationLengths;
    pointType = pt;
    branchIdentifier = id;
    setTree(tr);
}
Exemplo n.º 13
0
//compute the n., r. and v. tree given two vectors (with N rows) of s and h indexes
void allTrees_C(int *s, int *h, int * maxS, int *N, double * nvec, double * rvec, double * vvec)
{
	struct bintree * n = new struct bintree;
	struct bintree * r = new struct bintree;
	struct bintree * v = new struct bintree;
	setTree(1.0, n);
	setTree(1.0, r);
	setTree(1.0, v);
	//struct bintree *n = newtree(1);
	//struct bintree *r = newtree(1);
	//struct bintree *v = newtree(1);
	array2tree(nvec, maxS[0], n);
	array2tree(rvec, maxS[0], r);
	array2tree(vvec, maxS[0], v);
	allTrees(s, h, *maxS, *N, n, r, v);
	tree2array(r, rvec, maxS[0], 0);
	tree2array(n, nvec, maxS[0], 0);
	tree2array(v, vvec, maxS[0], 0);
	deleteTree(n);
	deleteTree(r);
	deleteTree(v);
}
Exemplo n.º 14
0
 GpModel::GpModel( int population_size ) :
 _population_size( population_size ),
 _trees( NULL ),
 _tree_generator( new TreeGenerator( ) ),
 _lower_fitness_better( true ),
 _tournament_selection( 2 ),
 _probability_crossover( 0.9 ),
 _probability_mutation( 0.01 ),
 _probability_reproduction( 1 - (_probability_crossover + _probability_mutation) ) {
     _trees = new TreeOfNodes* [getPopulationSize()];
     for (int i = 0; i < getPopulationSize(); ++i) {
         setTree(NULL, i);
     }
 }
Exemplo n.º 15
0
RateMeyerHaeseler::RateMeyerHaeseler(char *file_name, PhyloTree *tree, bool rate_type)
 : RateHeterogeneity()
{
	name = "+M";
	full_name = "Meyer & von Haeseler (2003)";
	dist_mat = NULL;
	setTree(tree);
	rate_file = file_name;
	rate_mh = rate_type;
	if (!rate_mh) {
		name="+CAT";
		full_name = "Stamatakis (2007) experimental";
	}
}
Exemplo n.º 16
0
    void GpModel::create( ) {
        for (int i = 0; i < getPopulationSize(); ++i) {
            setTree(getTreeGenerator().createRandomTree(), i);
        }
        g_operator[GO_CROSSOVER] = getProbabilityCrossover();
        if (getProbabilityReproduction() > getProbabilityMutation()) {
            g_operator[1] = getProbabilityReproduction();
            g_operator[2] = getProbabilityMutation();
        } else {
            g_operator[1] = getProbabilityMutation();
            g_operator[2] = getProbabilityReproduction();
        }

    }
Exemplo n.º 17
0
int OpenSWCDialog::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QDialog::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: { bool _r = run();
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 1: { bool _r = setTree((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        default: ;
        }
        _id -= 2;
    }
    return _id;
}
Exemplo n.º 18
0
int main()
{
	freopen("1036.in","r",stdin);
	freopen("1036.out","w",stdout);
	int n,m;dmax[0]=-INF;
	scanf("%d",&n);
	for(int i=1,p1,p2;i<=n-1;i++)
	{
		scanf("%d%d",&p1,&p2);
		addEdge(p1,p2);
		addEdge(p2,p1);
	}
	setTree(1);
	for(int i=1;i<=n;i++) scanf("%d",&val[i]);
	for(int i=1;i<=n;i++) access(i);
	scanf("%d",&m);
	char odr[11];
	for(int i=1,p1,p2;i<=m;i++)
	{
		scanf("%s%d%d",odr,&p1,&p2);
		if(odr[1]=='H')
			val[p1]=p2;
		else if(odr[1]=='M')
		{
			mkroot(p1);
			access(p2);
			splay(p2);
			printf("%d\n",Max(dmax[son[p2][0]],val[p2]));
		}
		else
		{
			mkroot(p1);
			access(p2);
			splay(p2);
			printf("%d\n",sum[son[p2][0]]+val[p2]);
		}
	}
	
}
Exemplo n.º 19
0
int main()
{
	int n,Q;
	scanf("%d%d",&n,&Q);
	for(int i=1,p1,p2;i<=n-1;i++)
	{
		scanf("%d%d",&p1,&p2);
		addEdge(p1,p2);
		addEdge(p2,p1);
	}
	setTree(1,0);
	add(1,1,n,le[1],ri[1],1);
	char s[3];
	for(int p;Q;Q--)
	{
		scanf("%s%d",s,&p);
		if(s[0]=='Q')
			printf("%d\n",query(1,1,n,le[p]));
		else
			add(1,1,n,le[p],ri[p],p);
	}
}
Exemplo n.º 20
0
OctreeElementPointer EntityTreeElement::createNewElement(unsigned char* octalCode) {
    auto newChild = EntityTreeElementPointer(new EntityTreeElement(octalCode));
    newChild->setTree(_myTree);
    return newChild;
}
void CtrlrPanelComponentProperties::refreshAll()
{
	refreshDynamicData();
	propertyPanel->refreshAll();
	setTree(treeToEdit, true);
}
Exemplo n.º 22
0
Stockholm::Stockholm (const vguard<FastSeq>& seq, const Tree& tree)
  : gapped (seq)
{
  setTree (tree);
}