소스 검색

Fix coefficients to make dead code actually be used sometimes.

Tomasz Zieliński 2 년 전
부모
커밋
55d7d7b9b5
2개의 변경된 파일9개의 추가작업 그리고 13개의 파일을 삭제
  1. 4 9
      lib/rmg/CZonePlacer.cpp
  2. 5 4
      lib/rmg/CZonePlacer.h

+ 4 - 9
lib/rmg/CZonePlacer.cpp

@@ -30,6 +30,8 @@ CZonePlacer::CZonePlacer(RmgMap & map)
 	stiffnessConstant(3e-3f),
 	stifness(0),
 	stiffnessIncreaseFactor(1.05f),
+	bestTotalDistance(1e10),
+	bestTotalOverlap(1e10),
 	map(map)
 {
 }
@@ -321,10 +323,6 @@ void CZonePlacer::placeZones(CRandomGenerator * rand)
 	//0. set zone sizes and surface / underground level
 	prepareZones(zones, zonesVector, underground, rand);
 
-	//remember best solution
-	float bestTotalDistance = 1e10;
-	float bestTotalOverlap = 1e10;
-
 	std::map<std::shared_ptr<Zone>, float3> bestSolution;
 
 	TForceVector forces;
@@ -673,7 +671,7 @@ void CZonePlacer::moveOneZone(TZoneMap& zones, TForceVector& totalForces, TDista
 	auto misplacedZone = misplacedZones.front().second;
 	float3 ourCenter = misplacedZone->getCenter();
 		
-	if (totalDistance > totalOverlap)
+	if ((totalDistance / (bestTotalDistance + 1)) > (totalOverlap / (bestTotalOverlap + 1)))
 	{
 		//Move one zone towards most distant zone to reduce distance
 
@@ -688,7 +686,7 @@ void CZonePlacer::moveOneZone(TZoneMap& zones, TForceVector& totalForces, TDista
 				targetZone = otherZone;
 			}
 		}
-		if (targetZone) //TODO: consider refactoring duplicated code
+		if (targetZone)
 		{
 			float3 vec = targetZone->getCenter() - ourCenter;
 			float newDistanceBetweenZones = (std::max(misplacedZone->getSize(), targetZone->getSize())) / mapSize;
@@ -696,13 +694,11 @@ void CZonePlacer::moveOneZone(TZoneMap& zones, TForceVector& totalForces, TDista
 			logGlobal->trace("direction is %s", vec.toString());
 
 			misplacedZone->setCenter(targetZone->getCenter() - vec.unitVector() * newDistanceBetweenZones); //zones should now overlap by half size
-			logGlobal->trace("New distance %f", targetZone->getCenter().dist2d(misplacedZone->getCenter()));
 		}
 	}
 	else
 	{
 		//Move misplaced zone away from overlapping zone
-		//FIXME: Does that ever happend? Check the number ranges and rescale if needed
 
 		float maxOverlap = 0;
 		for(const auto & otherZone : zones)
@@ -727,7 +723,6 @@ void CZonePlacer::moveOneZone(TZoneMap& zones, TForceVector& totalForces, TDista
 			logGlobal->trace("direction is %s", vec.toString());
 
 			misplacedZone->setCenter(targetZone->getCenter() + vec.unitVector() * newDistanceBetweenZones); //zones should now be just separated
-			logGlobal->trace("New distance %f", targetZone->getCenter().dist2d(misplacedZone->getCenter()));
 		}
 	}
 	//Don't swap that zone in next iteration

+ 5 - 4
lib/rmg/CZonePlacer.h

@@ -50,7 +50,7 @@ private:
 private:
 	int width;
 	int height;
-	//metric coefiicients
+	//metric coeficients
 	float scaleX;
 	float scaleY;
 	float mapSize;
@@ -59,9 +59,10 @@ private:
 	float stiffnessConstant;
 	float stifness;
 	float stiffnessIncreaseFactor;
-    //float a1, b1, c1, a2, b2, c2;
-	//CMap * map;
-	//std::unique_ptr<CZoneGraph> graph;
+
+	//remember best solution
+	float bestTotalDistance;
+	float bestTotalOverlap;
 
 	//distance [a][b] = number of zone connections required to travel between the zones
 	std::map<int, std::map<int, size_t>> distancesBetweenZones;