Пример #1
0
void FuelCellManager::OnLocationEntry()
{
  if (GetGameMode() == AMJU_MODE_EDIT)
  {
    // Add node to Scene Graph
    m_sceneNode = new Ve1Node(this);
    SceneNode* root = GetVe1SceneGraph()->GetRootNode(SceneGraph::AMJU_OPAQUE);
    Assert(root);
    root->AddChild(m_sceneNode);
    m_sceneNode->SetAABB(m_aabb);
  }
  // else... ????

  // Create fuel cells
  static int id = 20000;
  for (int i = 0; i < 10; i++)
  {
    FuelCell* f = new FuelCell;
    f->SetId(id++);

    float s = ROConfig()->GetFloat("fuel-cell-spread", 200.0f); 
    Vec3f r(Rnd(-s, s), Rnd(0, s), Rnd(-s, s));
    Vec3f p = GetPos() + r; 
    if (TerrainReady())
    {
      GetTerrain()->GetCollisionMesh()->GetY(Vec2f(p.x, p.z), &p.y); // TODO TEMP TEST Set all food to y = 0
    }
    f->SetPos(p);
    f->Load(0);
    TheGame::Instance()->AddGameObject(f);
    f->OnLocationEntry();
  }
}
Пример #2
0
//---------------------------------------------------------------------------
void PanelMakeCell(void)
{
	u8 r = Rnd(PANEL_MAX_REG_CNT - Panel.regCnt);
	u8 x, y;

	for(y=0; y<PANEL_MAX_CY; y++)
	{
		for(x=0; x<PANEL_MAX_CX; x++)
		{
			if(Panel.var[x][y] == 0)
			{
				if(r == 0)
				{
					goto End;
				}
				else
				{
					r--;
				}
			}
		}
	}

End:
	ASSERT(x < PANEL_MAX_CX && y < PANEL_MAX_CY);
	ASSERT(Panel.var[x][y] == 0);

	Panel.var[x][y] = (Rnd(10) >= 9) ? 2 : 1;
	Panel.regCnt++;

	AnimeSetMake(x, y, Panel.var[x][y]);
}
Пример #3
0
void Grenade::TimeTab(){
    YSpeed = YSpeed + 0.3;
    XPos = XPos + XSpeed;
    YPos = YPos + YSpeed;
    HLeft = HLeft - 1;
    NextSmoke = NextSmoke - 1;
    if (NextSmoke < 0) {
        NextSmoke = 2;
        FrmScreen.MakeSmoke(XPos, YPos, -XSpeed / 2, -YSpeed / 2);
    }
    if (HLeft < 1) {
        long i;
        FrmScreen.RemoveObject(this);
        for(i = 0; i <= 3; ++i){
            FrmScreen.Explosion(XPos + Rnd() * 30 - 15, YPos + Rnd() * 30 - 15, 1, 15, 15);
        }
        PlaySound(dsExplosion);
    }
    if (FrmScreen.GetMapLine((XPos), (YPos), XSpeed, YSpeed)) {
    	if (FrmScreen.GetMap(XPos + XSpeed, YPos - YSpeed / 2)) {
            XSpeed = -XSpeed / 1.2;
        }
        if (FrmScreen.GetMap(XPos + XSpeed, YPos + YSpeed)) {
            YSpeed = -YSpeed / 1.2 - 0.3;
        }
    }
    if (FrmScreen.isPlayer(XPos, YPos)) { HLeft = 0;}
}
Пример #4
0
void NOWA_ARMIA(aint A,aint ILU,aint RASA) {
	//	Procedure NOWA_ARMIA[A,ILU,RASA]

	astr A_S="";
	aint R=0,I=0,SILA=0,SPEED=0;

	if( A<20 ) {										//	   If A<20 : A$="Legion "+Str$(A+1)
		A_S=GS("039")+Str_S(A+1);
		ARMIA_S[A][0]=A_S;						//	      ARMIA$(A,0)=A$
	} else {												//	   Else
																	//	      'utajnianie
		ARMIA[A][0][TMAGMA]=30;				//	      ARMIA(A,0,TMAGMA)=30
		ARMIA[A][0][TKORP]=150+Rnd(50)+POWER;		//	      ARMIA(A,0,TKORP)=150+Rnd(50)+POWER
	}																//	   End If
	ARMIA[A][0][TAMO]=Rnd(200);			//	   ARMIA(A,0,TAMO)=Rnd(200)
	ARMIA[A][0][TE]=ILU;						//	   ARMIA(A,0,TE)=ILU
	R=RASA;													//	   R=RASA
	for(I=1;I<=ILU;++I) {						//	   For I=1 To ILU
		if(RASA==-1) R=Rnd(8);				//	      If RASA=-1 : R=Rnd(8) : End If
		NOWA_POSTAC(A,I,R);						//	      NOWA_POSTAC[A,I,R]
		SILA += ARMIA[A][I][TSI];			//	      Add SILA,ARMIA(A,I,TSI)
		SILA += ARMIA[A][I][TE];			//	      Add SILA,ARMIA(A,I,TE)
		SPEED += ARMIA[A][I][TSZ];		//	      Add SPEED,ARMIA(A,I,TSZ)
	}																//	   Next I
	//!!! niestandardowe
	if( ILU==0 ) ILU=1;
	SPEED=((SPEED/ILU)/5);					//	   SPEED=((SPEED/ILU)/5)
	ARMIA[A][0][TSZ]=SPEED;					//	   ARMIA(A,0,TSZ)=SPEED
	ARMIA[A][0][TSI]=SILA;					//	   ARMIA(A,0,TSI)=SILA
	ARMIA[A][0][TTRYB]=0;						//	   ARMIA(A,0,TTRYB)=0
}																	//	End Proc
Пример #5
0
void Haubits::Fire(double X, double Y, double XAim, double YAim, int Turn,
		bool isFire) {
	if (!isFire) { return;;}
	    if (MyPlayer->getItem(1) < 100 || MyPlayer->getItem(6) < 2 || MyPlayer->getItem(2) < 20) { return;;}
	    MyPlayer->setItem( 1, 0);
	    MyPlayer->CalcItem(6, -2);
	    MyPlayer->CalcItem(2, -30);
	    long i; Position Speed; Position Pos;
	    Speed.X = XAim / 10 * Turn;
	    Speed.Y = YAim / 10;
	    Pos.X = X + XAim / 3 * Turn;
	    Pos.Y = Y + YAim / 3;
	    FrmScreen.DrawPlPic(ddbExp, X - 15 + XAim / 4 * Turn, Y - 15 + YAim / 4, 0);
	    for(i = 0; i <= 100; ++i){
	        Pos.X = Pos.X + Speed.X;
	        Pos.Y = Pos.Y + Speed.Y;
	        if (FrmScreen.GetMap((Pos.X), (Pos.Y)) || FrmScreen.isPlayer((Pos.X), (Pos.Y))) { break;}
	    }
	    PlaySound(dsFire6);
	    if (i == 101) { return;;}
	    Pos.X = Pos.X - Speed.X;
	    Pos.Y = Pos.Y - Speed.Y;
	    FrmScreen.Explosion((Pos.X), (Pos.Y), 1, 5, 5);
	    for(i = 0; i <= 10; ++i){
	        auto nSpark = new Spark;
	        nSpark->Init((Pos.X), (Pos.Y), Rnd() * 10 - 5, Rnd() * 10 - 5);
	        FrmScreen.AddObject(nSpark);
	    }
	    for(i = 0; i <= 3; ++i){
	        FrmScreen.MakeSmoke((Pos.X), (Pos.Y), -Speed.X + Rnd() * 4 - 2, -Speed.Y + Rnd() * 4 - 2);
	    }
}
Пример #6
0
void Arena::Draw()
{
	float theta;

	glDisable( GL_BLEND );
	glDisable( GL_TEXTURE_2D );
	glColor3f( 0.0f, 0.0f, 1.0f );
	glBegin(GL_LINE_LOOP);
	for( theta=0.0f; theta<twopi; theta=theta + twopi/SEGMENTS)
	{
		float r=m_Radius + Rnd( -6.0f, 6.0f );
		glVertex2f( r*sin(theta), r*cos(theta));
	}
	glEnd();

	glColor3f( 0.5f, 0.5f, 1.0f );
	glBegin(GL_LINE_LOOP);
	for( theta=0.0f; theta<twopi; theta=theta + twopi/SEGMENTS)
	{
		float r=m_Radius + Rnd( -2.0f, 2.0f );
		glVertex2f( r*sin(theta), r*cos(theta));
	}
	glEnd();

	glColor3f( 0.9f, 0.9f, 1.0f );
	glBegin(GL_LINE_LOOP);
	for( theta=0.0f; theta<twopi; theta=theta + twopi/SEGMENTS)
	{
		float r=m_Radius + Rnd( -1.0f, 1.0f );
		glVertex2f( r*sin(theta), r*cos(theta));
	}
	glEnd();


	glEnable( GL_BLEND );
	glBlendFunc( GL_ONE, GL_ONE );
	glEnable( GL_TEXTURE_2D );
	glBindTexture( GL_TEXTURE_2D,m_Glow->ID() );
	glColor3f( 1.0f, 1.0f, 1.0f );
	glBegin( GL_TRIANGLE_STRIP );
	for( theta=0.0f; theta<twopi; theta=theta + twopi/SEGMENTS)
	{
		const float glowradius = 20.0f;
		float r1 = m_Radius-glowradius;
		float r2 = m_Radius+glowradius;

		vec2 p1( r1*sin(theta), r1*cos(theta) );
		vec2 p2( r2*sin(theta), r2*cos(theta) );

		glTexCoord2f( 0.0f, 0.0f );
		glVertex2f( p1.x, p1.y );

		glTexCoord2f( 0.0f, 1.0f );
		glVertex2f( p2.x, p2.y );
	}
	glEnd();
}
Пример #7
0
void Autopilot::Tick()
{
    if( Rnd(0.0f,1.0f) < 0.01 )
        m_X = Rnd( -1.0f, 1.0f );
    if( Rnd(0.0f,1.0f) < 0.01 )
        m_Y = Rnd( -1.0f, 0.0f );   // don't go backwards
    m_PrevBtnState = m_BtnState;
    m_BtnState = CTRL_BTN_FIRE;
}
Пример #8
0
void Shuffle(int *deck, int size)
{
  int i;
  for(i = 0; i < size; i++){
    deck[i] = i;          /* Deal a deck ! */
  }
  for(i = 0; i < size/2; i++){ /* shuffle the deck */
    SwapInt(& deck[Rnd(0, size - 1)], & deck[Rnd(0, size - 1)]);
  }
}
Пример #9
0
//---------------------------------------------------------------------------
void AstSetUnit(u8 num, s8 x, s8 y, u8 type, u8 step)
{
	ST_AST_DATA* p = &Ast.d[num];

	p->fx    = NUM2FIX(x);
	p->fy    = NUM2FIX(y);
	p->fmx   = (Rnd((1 + Ast.wave + step) * 4) + (1 + Ast.wave) * 2) * (RndIsBool() == TRUE ? 1 : -1);
	p->fmy   = (Rnd((1 + Ast.wave + step) * 4) + (1 + Ast.wave) * 2) * (RndIsBool() == TRUE ? 1 : -1);
	p->type  = type;
	p->step  = step;
	p->r     = (s8)__LPM(AstRadiusTable + step);
	p->isUse = TRUE;

	Ast.cnt++;
}
Пример #10
0
		/** Randomly selects a point in the given tree node by considering probabilities 
		 * Runtime: O(S*S + log(S*S))
		 */
		inline Eigen::Vector2f ProbabilityCellPoint(const Eigen::MatrixXf& m0, int scale, int x, int y)
		{
			x *= scale;
			y *= scale;
			const auto& b = m0.block(x, y, scale, scale);
			// build cdf
			std::vector<float> cdf(scale*scale);
			for(int i=0; i<scale; ++i) {
				for(int j=0; j<scale; ++j) {
					float v = b(j,i);
					int q = scale*i + j;
					if(q > 0) {
						cdf[q] = cdf[q-1] + v;
					}
					else {
						cdf[q] = v;
					}
				}
			}
			// sample in cdf
			boost::variate_generator<boost::mt19937&, boost::uniform_real<float> > rnd(
					Rnd(), boost::uniform_real<float>(0.0f, cdf.back()));
			float v = rnd();
			// find sample
			auto it = std::lower_bound(cdf.begin(), cdf.end(), v);
			int pos = std::distance(cdf.begin(), it);
			return Eigen::Vector2f(x + pos%scale, y + pos/scale);
		}
Пример #11
0
//---------------------------------------------------------------------------
void AstSetWave(void)
{
	u8 i;

	for(i=0; i<Ast.wave; i++)
	{
		if(RndIsBool() == TRUE)
		{
			AstSetUnit(i, Rnd(128), ((RndIsBool() == TRUE) ? 0 : 63), Rnd(4), 0);
		}
		else
		{
			AstSetUnit(i, ((RndIsBool() == TRUE) ? 0 : 127), Rnd(64), Rnd(4), 0);
		}
	}
}
Пример #12
0
static bool SetupBoxOverlaps(TestBase& test, udword nb_x, udword nb_y, float scale_x, float scale_y, float altitude, float box_radius)
{
	BasicRandom Rnd(42);

	const Point Extents(box_radius, box_radius, box_radius*2.0f);

	const float OneOverNbX = 1.0f / float(nb_x-1);
	const float OneOverNbY = 1.0f / float(nb_y-1);
	for(udword y=0;y<nb_y;y++)
	{
		const float CoeffY = 2.0f * ((float(y)*OneOverNbY) - 0.5f);
		for(udword x=0;x<nb_x;x++)
		{
			const float CoeffX = 2.0f * ((float(x)*OneOverNbX) - 0.5f);

			const Point Origin(CoeffX * scale_x, altitude, CoeffY * scale_y);

			Quat Q;
			UnitRandomQuat(Q, Rnd);
			const Matrix3x3 Rot = Q;

			test.RegisterBoxOverlap(OBB(Origin, Extents, Rot));
		}
	}
	test.mCreateDefaultEnvironment = false;
	return true;
}
Пример #13
0
TFfGGen::TStopReason TFfGGen::AddNodes(const int& GraphNodes, const bool& FloodStop) {
	printf("\n***ForestFire:  %s  Nodes:%d  StartNodes:%d  Take2AmbProb:%g\n", BurnExpFire ? "ExpFire" : "GeoFire", GraphNodes, StartNodes(), Take2AmbProb());
	printf("                FwdBurnP:%g  BckBurnP:%g  ProbDecay:%g  Orphan:%g\n", FwdBurnProb(), BckBurnProb(), ProbDecay(), OrphanProb());
	TExeTm ExeTm;
	int Burned1 = 0, Burned2 = 0, Burned3 = 0; // last 3 fire sizes
	// create initial set of nodes
	if (Graph.Empty()) { Graph = PNGraph::New(); }
	if (Graph->GetNodes() == 0) {
		for (int n = 0; n < StartNodes; n++) { Graph->AddNode(); }
	}
	int NEdges = Graph->GetEdges();
	// forest fire
	TRnd Rnd(0);
	TForestFire ForestFire(Graph, FwdBurnProb, BckBurnProb, ProbDecay, 0);
	// add nodes
	for (int NNodes = Graph->GetNodes() + 1; NNodes <= GraphNodes; NNodes++) {
		const int NewNId = Graph->AddNode(-1);
		IAssert(NewNId == Graph->GetNodes() - 1); // node ids have to be 0...N
		// not an Orphan (burn fire)
		if (OrphanProb == 0.0 || Rnd.GetUniDev() > OrphanProb) {
			// infect ambassadors
			if (Take2AmbProb == 0.0 || Rnd.GetUniDev() > Take2AmbProb || NewNId < 2) {
				ForestFire.Infect(Rnd.GetUniDevInt(NewNId)); // take 1 ambassador
			}
			else {
				const int AmbassadorNId1 = Rnd.GetUniDevInt(NewNId);
				int AmbassadorNId2 = Rnd.GetUniDevInt(NewNId);
				while (AmbassadorNId1 == AmbassadorNId2) {
					AmbassadorNId2 = Rnd.GetUniDevInt(NewNId);
				}
				ForestFire.Infect(TIntV::GetV(AmbassadorNId1, AmbassadorNId2)); // take 2 ambassadors
			}
			// burn fire
			if (BurnExpFire) { ForestFire.BurnExpFire(); }
			else { ForestFire.BurnGeoFire(); }
			// add edges to burned nodes
			for (int e = 0; e < ForestFire.GetBurned(); e++) {
				Graph->AddEdge(NewNId, ForestFire.GetBurnedNId(e));
				NEdges++;
			}
			Burned1 = Burned2;  Burned2 = Burned3;  Burned3 = ForestFire.GetBurned();
		}
		else {
			// Orphan (zero out-links)
			Burned1 = Burned2;  Burned2 = Burned3;  Burned3 = 0;
		}
		if (NNodes % Kilo(1) == 0) {
			printf("(%d, %d)  burned: [%d,%d,%d]  [%s]\n", NNodes, NEdges, Burned1, Burned2, Burned3, ExeTm.GetStr());
		}
		if (FloodStop && NEdges>GraphNodes && (NEdges / double(NNodes)>1000.0)) { // average node degree is more than 500
			printf(". FLOOD. G(%6d, %6d)\n", NNodes, NEdges);  return srFlood;
		}
		if (NNodes % 1000 == 0 && TimeLimitSec > 0 && ExeTm.GetSecs() > TimeLimitSec) {
			printf(". TIME LIMIT. G(%d, %d)\n", Graph->GetNodes(), Graph->GetEdges());
			return srTimeLimit;
		}
	}
	IAssert(Graph->GetEdges() == NEdges);
	return srOk;
}
Пример #14
0
static bool SetupCapsuleOverlaps(TestBase& test, udword nb_x, udword nb_y, float scale_x, float scale_y, float altitude, float capsule_radius)
{
	BasicRandom Rnd(42);

	const float OneOverNbX = 1.0f / float(nb_x-1);
	const float OneOverNbY = 1.0f / float(nb_y-1);
	for(udword y=0;y<nb_y;y++)
	{
		const float CoeffY = 2.0f * ((float(y)*OneOverNbY) - 0.5f);
		for(udword x=0;x<nb_x;x++)
		{
			const float CoeffX = 2.0f * ((float(x)*OneOverNbX) - 0.5f);

			const Point Origin(CoeffX * scale_x, altitude, CoeffY * scale_y);

			Quat Q;
			UnitRandomQuat(Q, Rnd);
			const Matrix3x3 Rot = Q;

//			const Point D = Rot[1] * capsule_radius;
			const Point D = Rot[1] * 10.0f;

			test.RegisterCapsuleOverlap(LSS(Segment(Origin-D, Origin+D), capsule_radius));
		}
	}
	test.mCreateDefaultEnvironment = false;
	return true;
}
Пример #15
0
	virtual bool OverlapAny_SpheresVsPlanetSide::CommonSetup()
	{
		TestBase::CommonSetup();
		mRepX = CreateRepXContext("Planetside_Statics.repx", 1.0f, false);

		const Point Min(0.0f, -20.f, 0.0f);
		const Point Max(1000.0f, 20.0f, 1000.0f);
		const Point Center = (Max + Min)*0.5f;
		const Point Extents = (Max - Min)*0.5f;

		BasicRandom Rnd(42);
		for(udword i=0;i<4096;i++)
		{
			Point p;
			UnitRandomPt(p, Rnd);
			Point Pos = Center + Extents*p;
//			Pos.y = 0.0f;
//			RegisterSphereOverlap(Sphere(Pos, 2.0f));
//			RegisterSphereOverlap(Sphere(Pos, 20.0f));
			RegisterSphereOverlap(Sphere(Pos, 10.0f));
//			RegisterSphereOverlap(Sphere(Pos, 1.0f));
		}
		mCreateDefaultEnvironment = false;
		return true;
	}
Пример #16
0
PAlignPair TAlignPair::LoadAcXml(const TStr& FNm, const int& MxSents) {
    printf("Loading %s ...\n", FNm.CStr());
    // get the lanugagne names
    TStr BaseNm = FNm.GetFMid();
    TStrV PartV; BaseNm.SplitOnAllCh('-', PartV);
    IAssertR(PartV.Len() == 3, "Bad file name: " + BaseNm);
    // prepare aligne pair
    PAlignPair AlignPair = TAlignPair::New(PartV[1], PartV[2]);
    // parse the XML
    PTransCorpus TransCorpus = TTransCorpus::LoadAC(FNm, MxSents * 4);
    // select subset of sentences which will go into aligned corpus
    const int AllSents = TransCorpus->GetSentences();
    TIntV SentIdV(AllSents, 0);
    for (int SentId = 0; SentId < AllSents; SentId++) {
        SentIdV.Add(SentId); 
    }
    if (MxSents != -1 && AllSents > MxSents) {
    	TRnd Rnd(1);
        SentIdV.Shuffle(Rnd);
        SentIdV.Trunc(MxSents);
    }
    // add the sentences to the bow
    const int Sents = SentIdV.Len();
    for (int SentIdN = 0; SentIdN < Sents; SentIdN++) {
        const int SentId = SentIdV[SentIdN];
        const TStr& Sent1 = TransCorpus->GetOrgStr(SentId);
        const TStr& Sent2 = TransCorpus->GetRefTransStrV(SentId)[0];
        AlignPair->AddSent(Sent1, Sent2);
    }
    // finish the alignment pair
    AlignPair->Def();
    return AlignPair;
}
Пример #17
0
	virtual bool CapsuleOverlapAny_TestZone::CommonSetup()
	{
		TestBase::CommonSetup();

		LoadMeshesFromFile_(*this, "testzone.bin");

//		return Setup_PotPourri_Raycasts(*this, 4096, 10.0f);
		mCreateDefaultEnvironment = false;
		UnregisterAllCapsuleOverlaps();

		IndexedSurface* IS = GetFirstSurface();
		const Point* V = IS->GetVerts();
		BasicRandom Rnd(42);
		const float R = 1.0f;
//		const float R = 0.1f;
//		const float R = 10.0f;
		for(udword i=0;i<IS->GetNbFaces();i++)
		{
			const IndexedTriangle* T = IS->GetFace(i);
			Point Center;
			T->Center(V, Center);

//			Center.y += 10.0f;

			Quat Q;
			UnitRandomQuat(Q, Rnd);

			Matrix3x3 M = Q;
			const Point D = M[1]*4.0f;
//			const Point D = M[1]*2.0f;

			RegisterCapsuleOverlap(LSS(Segment(Center-D, Center+D), R));	// 1.95
		}
		return true;
	}
Пример #18
0
void testrndloop(const int times, int seed)
{
    int i;
    for (i = 0; i < times; i++)
    {
        printf("Rnd(%d) = %.7f\n", seed, Rnd(seed));
    }
}
Пример #19
0
void Grenade::Init(double X, double Y, double Xs, double Ys){
    XPos = X;
    YPos = Y;
    XSpeed = Xs;
    YSpeed = Ys;
    HLeft = 20 + Rnd() * 5;
    NextSmoke = 0;
}
Пример #20
0
long int GenerateLong()
{
	long int number;
	const long int lowerbound = 0L;
	const long int upperbound = 0x7ffffffeL;
	number = ((upperbound - lowerbound + 1) * Rnd(1) + lowerbound);
	return number;
}
Пример #21
0
void Tropelet::MakeWarp(long Player){
    long i; long X; long Y;
    long MapX; long MapY;
        auto PlayerToWarp = frmScreen.getPlayer(Player);
        MapX = frmScreen.GetMapWidth();
        MapY = frmScreen.GetMapHeight();
        FrmScreen.MakeSmoke(PlayerToWarp->XPos, PlayerToWarp->YPos, -3, 0, 1);
        FrmScreen.MakeSmoke(PlayerToWarp->XPos, PlayerToWarp->YPos, 3, 0, 1);
    for(i = 0; i <= 1000; ++i){
        X = (MapX - 20) * Rnd() + 10;
        Y = (MapY - 20) * Rnd() + 10;
        if (FrmScreen.GetMap(X, Y) == mAir) { break;}
    }
    PlayerToWarp->XPos = X;
    PlayerToWarp->YPos = Y;
    FrmScreen.MakeSmoke(PlayerToWarp->XPos, PlayerToWarp->YPos, -3, 0, 1);
    FrmScreen.MakeSmoke(PlayerToWarp->XPos, PlayerToWarp->YPos, 3, 0, 1);
}
Пример #22
0
		/** Selects a random point in the tree node using uniform distribution */ 
		inline Eigen::Vector2f RandomCellPoint(int scale, int x, int y, float gamma)
		{
			float sf = static_cast<float>(scale);
			float xf = static_cast<float>(x);
			float yf = static_cast<float>(y);
			boost::variate_generator<boost::mt19937&, boost::uniform_real<float> > delta(
					Rnd(), boost::uniform_real<float>(0.5f-gamma, 0.5f+gamma));
			return Eigen::Vector2f(sf*(xf + delta()), sf*(yf + delta()));
		}
Пример #23
0
void NPointCrossover(IPTR p1, IPTR p2, IPTR c1, IPTR c2, Population *p )
{
/* p1,p2,c1,c2,m1,m2,mc1,mc2 */
  ChromType *pi1,*pi2,*ci1,*ci2;
  int i, k;
  int *xp;
  int lchrom;

  lchrom = p->chromLength;
  pMut = p->pMut;
  pCross = p->pCross;

  pi1 = p1->chrom;
  pi2 = p2->chrom;
  ci1 = c1->chrom;
  ci2 = c2->chrom;

  
  IndividualCopy(p1, c1);
  IndividualCopy(p2, c2);

  /* only Mutation */
  if(!Flip(pCross)) {
    Mutate(c1, pMut);
    Mutate(c2, pMut);
    return;
  }
  /* Uniform Crossover */
  if(p->nXPoints == lchrom){
    for(i = 0; i < lchrom; i++){
      ci1[i] = (Flip(0.5) ? pi1[i] : pi2[i]);
      ci2[i] = (Flip(0.5) ? pi1[i] : pi2[i]);
    }
    Mutate(c1, pMut);
    Mutate(c2, pMut);
    return;
  }

  /* N point crossover */
  xp = (int *) calloc (lchrom, sizeof(int));
  for(i = 1; i < p->nXPoints; i++){
    xp[Rnd(0, lchrom - 1)] = 1;
  }
  k = 0;
  for(i = 0; i < lchrom; i++){
    if(xp[i] == 1) {
      k++; 
    }
    ci1[i] = MuteX(pi1[i], pi2[i], k%2);
    ci2[i] = MuteX(pi2[i], pi1[i], k%2);
  }
  /* end crossover */
  Mutate(c1, pMut);
  Mutate(c2, pMut);
  free(xp);
}
Пример #24
0
		/** Randomly rounds a float up or down s.t. the expected value is the given value */
		inline unsigned int RandomRound(float x)
		{
			if(x <= 0.0f) {
				return 0;
			}
			float a = std::floor(x);
			float r = x - a;
			boost::variate_generator<boost::mt19937&, boost::uniform_real<float> > uniform01(
					Rnd(), boost::uniform_real<float>(0.0f,1.0f));
			return a + (uniform01() >= r ? 0.0f : 1.0f);
		}
Пример #25
0
/// <summary>
/// Greates a random input image, used for testing purposes
/// </summary>
void Ttopmap::randomInputs()
{
  int x,y;

  for (x = 0;x<inputs_width;x++)
    {
    for (y = 0;y<inputs_height;y++)
      {
      inputs[x][y] = (unsigned char)(Rnd()*255);
      }
    }
}
Пример #26
0
void LearnEmbeddings(TVVec<TInt, int64>& WalksVV, int& Dimensions, int& WinSize,
 int& Iter, bool& Verbose, TIntFltVH& EmbeddingsHV) {
  TIntIntH RnmH;
  TIntIntH RnmBackH;
  int64 NNodes = 0;
  //renaming nodes into consecutive numbers
  for (int i = 0; i < WalksVV.GetXDim(); i++) {
    for (int64 j = 0; j < WalksVV.GetYDim(); j++) {
      if ( RnmH.IsKey(WalksVV(i, j)) ) {
        WalksVV(i, j) = RnmH.GetDat(WalksVV(i, j));
      } else {
        RnmH.AddDat(WalksVV(i,j),NNodes);
        RnmBackH.AddDat(NNodes,WalksVV(i, j));
        WalksVV(i, j) = NNodes++;
      }
    }
  }
  TIntV Vocab(NNodes);
  LearnVocab(WalksVV, Vocab);
  TIntV KTable(NNodes);
  TFltV UTable(NNodes);
  TVVec<TFlt, int64> SynNeg;
  TVVec<TFlt, int64> SynPos;
  TRnd Rnd(time(NULL));
  InitPosEmb(Vocab, Dimensions, Rnd, SynPos);
  InitNegEmb(Vocab, Dimensions, SynNeg);
  InitUnigramTable(Vocab, KTable, UTable);
  TFltV ExpTable(TableSize);
  double Alpha = StartAlpha;                              //learning rate
#pragma omp parallel for schedule(dynamic)
  for (int i = 0; i < TableSize; i++ ) {
    double Value = -MaxExp + static_cast<double>(i) / static_cast<double>(ExpTablePrecision);
    ExpTable[i] = TMath::Power(TMath::E, Value);
  }
  int64 WordCntAll = 0;
// op RS 2016/09/26, collapse does not compile on Mac OS X
//#pragma omp parallel for schedule(dynamic) collapse(2)
  for (int j = 0; j < Iter; j++) {
#pragma omp parallel for schedule(dynamic)
    for (int64 i = 0; i < WalksVV.GetXDim(); i++) {
      TrainModel(WalksVV, Dimensions, WinSize, Iter, Verbose, KTable, UTable,
       WordCntAll, ExpTable, Alpha, i, Rnd, SynNeg, SynPos); 
    }
  }
  if (Verbose) { printf("\n"); fflush(stdout); }
  for (int64 i = 0; i < SynPos.GetXDim(); i++) {
    TFltV CurrV(SynPos.GetYDim());
    for (int j = 0; j < SynPos.GetYDim(); j++) { CurrV[j] = SynPos(i, j); }
    EmbeddingsHV.AddDat(RnmBackH.GetDat(i), CurrV);
  }
}
Пример #27
0
int main(int argc, char* argv[]) {
	Env = TEnv(argc, argv, TNotify::StdNotify);
	Env.PrepArgs(TStr::Fmt("agmgen. build: %s, %s. Time: %s", __TIME__, __DATE__, TExeTm::GetCurTm()));
	TExeTm ExeTm;
	Try
	const TStr InFNm = Env.GetIfArgPrefixStr("-i:", "DEMO", "Community affiliation data");
	const TStr OutFPrx = Env.GetIfArgPrefixStr("-o:", "agm", "out file name prefix");
	const int RndSeed = Env.GetIfArgPrefixInt("-rs:",10,"Rnd Seed");
	const double DensityCoef= Env.GetIfArgPrefixFlt("-a:",0.6,"Power-law Coefficient a of density (density ~ N^(-a)");
	const double ScaleCoef= Env.GetIfArgPrefixFlt("-c:",1.3,"Scaling Coefficient c of density (density ~ c");

	TRnd Rnd(RndSeed);
	TVec<TIntV> CmtyVV;
	if(InFNm=="DEMO") {
		CmtyVV.Gen(2);
		TIntV NIdV;
		for(int i=0;i<25;i++) {
			TIntV& CmtyV = CmtyVV[0];
			CmtyV.Add(i+1);
		}
		for(int i=15;i<40;i++) {
			TIntV& CmtyV = CmtyVV[1];
			CmtyV.Add(i+1);
		}
	}
	else {
		TVec<TIntV> CmtyVV;
	  TSsParser Ss(InFNm, ssfWhiteSep);
	  while (Ss.Next()) {
			if(Ss.GetFlds()>0) {
				TIntV CmtyV;
				for(int i=0;i<Ss.GetFlds();i++) {
					if(Ss.IsInt(i)){CmtyV.Add(Ss.GetInt(i));}
				}
				CmtyVV.Add(CmtyV);
			}
	  }
		printf("community loading completed (%d communities)\n",CmtyVV.Len());
	}
	PUNGraph AG = TAGM::GenAGM(CmtyVV,DensityCoef,ScaleCoef,Rnd);
	TSnap::SaveEdgeList(AG,OutFPrx + ".edgelist.txt");
	if(AG->GetNodes()<50) {
		TAGM::GVizComGraph(AG,CmtyVV,OutFPrx + ".graph.gif");
	}
	Catch
  printf("\nrun time: %s (%s)\n", ExeTm.GetTmStr(), TSecTm::GetCurTm().GetTmStr().CStr());
  return 0;
}
Пример #28
0
/// <summary>
/// Create some initial random weights in the given range
/// </summary>
/// <param name="minVal">Minimum weight value</param>
/// <param name="maxVal">Maximum weight value</param>
void Ttopmap::initWeights(float minVal, float maxVal)
{
  int x,y,xx,yy;

  for (x=0;x<map_width;x++)
    {
    for (y=0;y<map_height;y++)
      {
      for (xx=0;xx<inputs_width;xx++)
        {
        for (yy=0;yy<inputs_height;yy++)
          unit[x][y][xx][yy] = minVal + (Rnd() * (maxVal - minVal));
        }
      }
    }
}
Пример #29
0
/* Private (static) Functions Section
 *-------------------------------------------------------------------
 */
void testrnd()
{
    puts("Testing Rnd() function");

    puts("\ntesting with negativee number (-10)");
    testrndloop(3, -10);

    Randomize(0x50000L);
    Rnd(1);
    puts("\ntesting with 0 as seed");
    testrndloop(3, 0);

    Randomize(0x50000L);
    puts("\ntesting with positive number (1)");
    testrndloop(8, 1);

}
Пример #30
0
// Test graph generators
TYPED_TEST(GraphPercolationTest, PercolationThreshold) {

  typedef TypeParam TGraph;
  typedef TPt<TGraph> PGraph;

  int Nodes = 100;
  
  PGraph Graph;
  
  int rep = 100;
  double p, tol = 1e-3, lowerBound = 0.0, upperBound = 1.0;
  
  TRnd Rnd(0);
  
  // Line graph   
  
  Graph = TSnap::GenLine<PGraph>(Nodes);
  
  printf("Line\n====\n");
  printf("Nodes = %d\n", Graph->GetNodes());
  printf("Edges = %d\n", Graph->GetEdges());
  p = TSnap::FindPercolationThreshold(Graph, tol, lowerBound, upperBound, rep);
  printf("p = %f\n", p);
  
  // Line graph   
  
  Graph = TSnap::GenGrid<PGraph>((int) round(sqrt(Nodes)), (int) round(sqrt(Nodes)));
  
  printf("Grid\n====\n");
  printf("Nodes = %d\n", Graph->GetNodes());
  printf("Edges = %d\n", Graph->GetEdges());
  p = TSnap::FindPercolationThreshold(Graph, tol, lowerBound, upperBound, rep);
  printf("p = %f\n", p);
  
  // Full graph 
  
  Graph = TSnap::GenFull<PGraph>(Nodes);
  
  printf("Full\n====\n");
  printf("Nodes = %d\n", Graph->GetNodes());
  printf("Edges = %d\n", Graph->GetEdges());
  p = TSnap::FindPercolationThreshold(Graph, tol, lowerBound, upperBound, rep);
  printf("p = %f\n", p);
  
}