Browse Source

update cell algo

researchman 7 years ago
parent
commit
ae7e8f4653
5 changed files with 266 additions and 167 deletions
  1. 1 24
      SyncTime/SyncManager.cpp
  2. 1 1
      YAServer.vcxproj.user
  3. 0 7
      YAServerDlg.cpp
  4. 8 2
      algorithm/cell/cell_struct.h
  5. 256 133
      classdef.cpp

+ 1 - 24
SyncTime/SyncManager.cpp

@@ -22,10 +22,7 @@ HostServer::SyncManager::SyncManager()
 void HostServer::SyncManager::init()
 {
 	InitializeCriticalSectionAndSpinCount(&m_csSyncTime, 4000);
-	//InitializeCriticalSection(&m_csCalcLiner);
     _anchors.swap(unordered_map<unsigned long long, Position>());
-	//_syncTimeMsgs.clear();
-	//_historySync.clear();
     _distance.swap(unordered_map<unsigned long long,unordered_map<unsigned long long, double>>());
 	logDir = ".\\synclog\\";
 
@@ -162,10 +159,6 @@ bool HostServer::SyncManager::updateSync(unsigned long long rootIdCode, int idx,
 		}
         _historySync[rootIdCode][idx_synctime].HistSync[localIdCode].TimeDelay(timeDelay);
 
-
-		//debug_print_syslog(0, "Delay info, syncnum:%d, station id: 0x%x, timeDelay:%I64u", 
-		//                 SyncNum, localIdCode, timeDelay);
-
 		if(isOutputLog){
 			char filename[100];
 			char temp[200]; 
@@ -180,7 +173,6 @@ bool HostServer::SyncManager::updateSync(unsigned long long rootIdCode, int idx,
 
 			sprintf_s(filename, "%s\\%d.log", logDir.c_str(), localIdCode>>8);
 			ofstream outfile(filename, ofstream::app); 
-			//sprintf(temp, "%d, %d, %I64d, %I64d\r", SyncNum, dd, receiveTime, timeDelay );
 			sprintf_s(temp, "sn:%d, up:%d, rec:%I64d, snd:%I64d, del:%I64d, crt:%I64d, r_crs:%d, s_crs:%d\r", SyncNum, dd, receiveTime, sendTime, timeDelay, aa, bb, cc); 
 			outfile << temp;
 		}
@@ -195,11 +187,9 @@ bool HostServer::SyncManager::updateSync(unsigned long long rootIdCode, int idx,
 
 unsigned long long HostServer::SyncManager::calTimeByLinar(TagMsg &tag)
 {
-	//EnterCriticalSection(&m_csCalcLiner);
 	EnterCriticalSection(&m_csSyncTime);
     // 获取历史记录中与此tag最近的两条
     deque<SyncTime> hisSync;
-    //ofstream fout("test/linar_513.txt",ios::app);
 
 	unsigned long long rootIdCode = tag.SyncRootIdCode;
 
@@ -209,7 +199,6 @@ unsigned long long HostServer::SyncManager::calTimeByLinar(TagMsg &tag)
 		unordered_map<unsigned long long, SyncTimeMsg>::iterator it = _syncTimeMsgs[rootIdCode][idx].SyncTimeMsgs.find(tag.StationIdCode);
 		if(it != _syncTimeMsgs[rootIdCode][idx].SyncTimeMsgs.end()){
 			if(it->second.SyncLevel() == 0){
-				//LeaveCriticalSection(&m_csCalcLiner);
 				LeaveCriticalSection(&m_csSyncTime);
 				return tag.ReceiveTime;
 			}
@@ -230,7 +219,6 @@ unsigned long long HostServer::SyncManager::calTimeByLinar(TagMsg &tag)
     }
     // 如果满足条件的历史记录不足两个则返回
     if(hisSync.size() < 2){
-		//LeaveCriticalSection(&m_csCalcLiner);
 		LeaveCriticalSection(&m_csSyncTime);
 		return LLONG_MAX;
 	}
@@ -265,12 +253,6 @@ unsigned long long HostServer::SyncManager::calTimeByLinar(TagMsg &tag)
 		y2 -=TIME_MAX;
 	}
 
-	// y1 = k*x1 + b;
-	// y2 = k*x2 + b;
-
-	// k = (x1-x2)/(y1-y2);
-	// b = y1 - k*x1; 
-
     Eigen::Matrix3d a;
     a << x1 ,1 , 0,
          x2 ,1 , 0,
@@ -303,8 +285,6 @@ void HostServer::SyncManager::updateDistance(unsigned int localId, unsigned char
     // 删除所有版本的消息记录
 	_historySync.clear();
 	_syncTimeMsgs.clear();
-    //_historySync.swap(unordered_map<unsigned short, unordered_map<unsigned long long, SyncTime>>());
-    //_syncTimeMsgs.swap(unordered_map<unsigned short, unordered_map<unsigned long long, SyncTimeMsg>>());
 }
 
 void HostServer::SyncManager::updateAnchor(unsigned int localId, unsigned char localAntNum, double x, double y, double z)
@@ -338,13 +318,10 @@ void HostServer::SyncManager::deleteAnchor(unsigned int localId, unsigned char l
     // 删除所有版本的消息记录
 	_historySync.clear();
 	_syncTimeMsgs.clear();
-    //_historySync.swap(unordered_map<unsigned short, unordered_map<unsigned long long, SyncTime>>());
-    //_syncTimeMsgs.swap(unordered_map<unsigned short, unordered_map<unsigned long long, SyncTimeMsg>>());
 }
 
 HostServer::SyncManager::~SyncManager()
 {
-	//DeleteCriticalSection(&m_csCalcLiner);
 	DeleteCriticalSection(&m_csSyncTime);
 }
 
@@ -368,4 +345,4 @@ int HostServer::SyncManager::FindHisSyncTime(unsigned long long rootIdCode, unsi
 		}
 	}
 	return idx;
-}
+}

+ 1 - 1
YAServer.vcxproj.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
-    <ShowAllFiles>false</ShowAllFiles>
+    <ShowAllFiles>true</ShowAllFiles>
   </PropertyGroup>
 </Project>

+ 0 - 7
YAServerDlg.cpp

@@ -13500,13 +13500,6 @@ void CYAServerDlg::deal_card_msg( std::shared_ptr<Card> card/*Card* card*/, bool
 				if(PDT_DOWN ==  card->p_reader->pos_state)
 				{
 					card->add_dist(dist);
-
-					if (card->card_id == "0020000001074" && card->accelerate_state != 0)
-					{
-						char log[100] = {0};
-						sprintf_s(log,"card_id: %s, as: %d",card->card_id.c_str(),card->accelerate_state);
-						Log::write_log(FILE_TYPE::SYS_S,log,true);
-					}
 				}
 				else
 				{

+ 8 - 2
algorithm/cell/cell_struct.h

@@ -72,6 +72,7 @@ class Cell{
 public:
 	Cell(){
 		strSubjectReader = "";
+		strOriginReaderName = "";
 		id = 0;
 		nStep = 0;
 		minReaderId = maxReaderId = 0;
@@ -81,6 +82,7 @@ public:
 		isFit = isOverThre = false;
 		isChangePath = false;
 		top.x = top.y = bottom.x = bottom.y = left.x = left.y = right.x = right.y = 0;
+		originId = 0;
 
 		::GetLocalTime(&deal_time);
 		
@@ -94,10 +96,12 @@ public:
 	int maxReaderId;	//此格子所属的分站路径中的最大分站
 	int nStep;			//距离上一次格子的步进
 	int dataSource;	    //数据来源,0为未知,1为定位算法生成,2为定时器内生成
+	int originId;		//原始定位坐标转换的原始格子id
 
 	int card_stamp_time;	//卡的ct号
 
-	std::string strSubjectReader;	//格子所属分站名称
+	std::string strSubjectReader;		//格子所属分站名称
+	std::string strOriginReaderName;	//原始格子所属分站名,通过原始格子号+此属性,可以唯一确定格子的中心点坐标
 
 	point top,bottom,left,right;	//格子的4个顶点位置
 	
@@ -137,7 +141,9 @@ public:
 		isOverThre = c.isOverThre;
 		isChangePath = c.isChangePath;
 		deal_time = c.deal_time;
-		//interval_time = c.interval_time;
+		originId = c.originId;
+		strOriginReaderName = c.strOriginReaderName;
+		realId = c.realId;
 
 		return *this;
 	}

+ 256 - 133
classdef.cpp

@@ -1929,7 +1929,7 @@ void Card::get_coordinate( int cnt )
 		this->output_y = this->y;
 	}
 
-	if ((isNeedWrited || nStartLocateCounts<6) && m_nCalcSyncNum > 0)
+	if ((isNeedWrited || nStartLocateCounts<6) && m_nCalcSyncNum > 0 && ret == 0)
 	{
 		std::string flag1 = is_fit_pos?"Y":"N";
 		int nSource1 = 1;		
@@ -3938,6 +3938,9 @@ int Card::DiscreteLocate(int cnt)
 				return 1;
 			}
 
+			/*originCellId = 0;
+			originCellReaderName = "";*/
+
 			std::shared_ptr<POS> pos = std::make_shared<POS>();
 			//3.算法定位	
 			std::vector<std::shared_ptr<POS>> udm_pos;
@@ -3948,21 +3951,44 @@ int Card::DiscreteLocate(int cnt)
 			//b.可能有解,但解不正确,比如解的位置在4727,-100,但选出的解是4727,-200
 			ret = ChooseOneSolution(pRdm, udm_pos, pos);
 			SaveOriginDataBeforeFilter(pos);
+			if (ret)
+			{
+				return 1;
+			}
 			bool bRet = false;
 			bRet = LocateAlgorithm::IsOnMap(pos,pTdoaReaderPathMap);
 			if (!bRet)
 			{
 				return 1;
 			}
+			if (card_id == "0020000001024" && time_stamp_cal == 1980)
+			{
+				int aa = 1;
+				aa = his_cell.size();
+			}
 			if (ret)
 			{
+				if (his_cell.size() < 5)
+				{
+					return 1;
+				}
 				//根据上一次数据计算格子数,并根据上一次方向进行偏移
-				double y = 0;
-				y = fit_k*this->time_stamp_cal + fit_b;
+				//double y = 0;
+				//std::list<std::shared_ptr<Cell>>::iterator it = his_cell.begin();
+
+				//y = fit_k*(this->time_stamp_cal - (*it)->card_stamp_time + 1) + fit_b;
 
-				int nCellId = int(y);
-				//将新格子的信息除了格子id信息
-				cell = FindCell(curCellReaderName,nCellId);
+				//int nCellId = int(y);
+				////将新格子的信息除了格子id信息
+				//cell = FindCell(curCellReaderName,nCellId);
+				//如果从多解中未选出解,则按上一次格子的步进匀速运动
+				int nStep = 1;
+				if (last_cell->nStep > 1)
+				{
+					nStep = last_cell->nStep;
+				}
+				std::shared_ptr<Cell> cell = GetNextCell(last_cell,nIncrease,nStep,nullptr);
+				cell->originId = cell->id;
 			}else{
 				std::shared_ptr<POS> tmp_pos = std::make_shared<POS>();
 				//获取分站信息
@@ -3971,118 +3997,178 @@ int Card::DiscreteLocate(int cnt)
 
 				if (ret == 0)
 				{	
+					//将坐标转为格子信息
 					cell = Position2Cell(tmp_pos);
 					if (cell)
 					{
 						originCellId = cell->id;
 						originCellReaderName = cell->strSubjectReader;
 						cell->card_stamp_time = time_stamp_cal;
+						cell->originId = cell->id;
+						cell->strOriginReaderName = cell->strSubjectReader;
+						nStartLocateCounts++;
 
-						if (his_cell.size() > 100)
+						/*if (his_cell.size() > 100)
 						{
-							his_cell.pop_front();
-						}
+						his_cell.pop_front();
+						}*/
 
 						int cellIdOffset = 0;
-						string name = "";
 						int diff_ct = 0;
 						int thre_value = 0;
+						bool isAdded = false;
+						string name = "";
 
 						if (!is_algo_first_location)
 						{
+							//不是第一次定位,需要判断是否大跳
 							if (last_cell)
 							{
-								name = last_cell->strSubjectReader;
+								//name = last_cell->strSubjectReader;
+								name = last_cell->strOriginReaderName;
 								diff_ct = abs(cell->card_stamp_time - last_cell->card_stamp_time);
 							}
-							if (cell->strSubjectReader == name)
+							//判断当前格子和上一次格子是否在两相同的分站之间
+							//if (cell->strSubjectReader == name)
+							if (cell->strOriginReaderName == name)
 							{
-								cellIdOffset = ceil(abs(cell->id - last_cell->id));
+								//相同,则直接用格子id相减
+								//cellIdOffset = ceil(abs(cell->id - last_cell->id));
+								//相同,使用格子的原始id相减
+								cellIdOffset = ceil(abs(cell->originId - last_cell->originId));
 							}
 							else{
+								//不相同,通过计算两次位移之间的距离d,并用d除以格子的长度计算格子偏移数
 								double distance = sqrt(pow(tmp_pos->cx - this->x,2) + pow(tmp_pos->cy - this->y,2)) * map_scale;
 								cellIdOffset = ceil(distance / CELL_WIDTH);
 							}
-							//允许调整按ct号的最大格子数
 
+							//允许调整按ct号的最大格子数
 							thre_value = MAX_CELL_FORWARD_JUMP;
 							if (diff_ct > 0)
 							{
 								thre_value = MAX_CELL_FORWARD_JUMP*diff_ct;
 							}
 
+							//判断此次格子和上一次格子之间存在的格子数是否超过阈值
 							if (cellIdOffset < thre_value){
-								his_cell.push_back(cell);
+								//his_cell.push_back(cell);
+								//没超过,加入到队列内计算
+								colourfulCloudsChasingTheMoon(cell,his_cell);
+								isAdded = true;
 							}
-						}else{
-							his_cell.push_back(cell);
-						}
 
-						if (his_cell.size() > 4)
-						{
-							if (cellIdOffset > thre_value)
-							{
-								//根据上一次数据计算格子数,并根据上一次方向进行偏移
-								double y = 0;
-								y = fit_k*this->time_stamp_cal + fit_b;
-
-								int nCellId = int(y);
-								//将新格子的信息除了格子id信息
-								cell = FindCell(curCellReaderName,nCellId);
-							} 
-							else
+							if (his_cell.size() > 4)
 							{
-								double ctArray[5] = {0.0};
-								double cidArray[5] = {0};
-
-								//获取新5个元素的值
-								int i = 4;
-								for (std::list<std::shared_ptr<Cell>>::reverse_iterator rit = his_cell.rbegin();rit != his_cell.rend();++rit)
+								if (cellIdOffset > thre_value)
 								{
-									ctArray[i] = (*rit)->card_stamp_time;
-									cidArray[i] = (*rit)->id;
-									i--;
-									if (i<0)
-									{
-										break;
-									}
-								}
+									int tmpOriginId = 0;
+									std::string tmpOriginReaderName = "";
+									tmpOriginId = cell->originId;
+									tmpOriginReaderName = cell->strOriginReaderName;
 
-								//第五点和前4点拟合的直线方程y = kx + b的k,b
-								Fit f;
-								f.linearFit(ctArray,cidArray,5,true);
-								double k = f.getSlope();
-								double b = f.getIntercept();
-								//取得垂直线的k
-								/*double k1 = -1.0/k;
-								double b1 = cidArray[4] - k1*ctArray[4];*/
+									//根据上一次数据计算格子数,并根据上一次方向进行偏移
+									double y = 0;
+									std::list<std::shared_ptr<Cell>>::iterator it = his_cell.begin();
 
-								fit_k = k;
-								fit_b = b;
+									y = fit_k*(this->time_stamp_cal - (*it)->card_stamp_time + 1) + fit_b;
 
-								if (f.getR()!=1)
-								{
-									if (abs(k) < 5 && f.getR() < 0.55)
-									{
-										*cell = *last_cell;
-									} 
-									else
+									int nCellId  =0 ;
+									std::string strReaderName = "";
+									if ((*it)->strOriginReaderName != cell->strOriginReaderName)
 									{
-										double y = fit_k*ctArray[4] + b;
-
-										int newCellId = LocateAlgorithm::round(y);
-
-										//将新格子id进行更新
-										if (newCellId < mpCellPath->find(originCellReaderName)->second.size())
-										{
-											//cell->id = newCellId;
-											cell = FindCell(originCellReaderName,newCellId);
-										}else{
-											TRACE(_T("cell id is more bigger.\r\n"));
+										int nRealId = 0;
+										nCellId = LocateAlgorithm::round(y);
+										//换基站了
+										int first_min = (*it)->minReaderId; //first_cell_temp对应的最小分站
+										int first_max = (*it)->maxReaderId; //first_cell_temp对应的最大分站
+										int cell_min = cell->minReaderId; //cell对应的最小分站
+										int cell_max = cell->maxReaderId; //cell对应的最大分站
+
+										if(first_min == cell_min){
+											//nRealId = nCellId; 	
+											if (nCellId == 0)
+											{
+												nRealId = 1;
+												strReaderName = cell->strSubjectReader;
+											}else if(nCellId > 0){
+												nRealId = nCellId;
+												strReaderName = (*it)->strSubjectReader;
+											}else if(nCellId < 0){
+												nRealId = abs(nCellId);
+												strReaderName = cell->strSubjectReader;
+											}
+										}
+										if(first_min == cell_max){
+											//nRealId = mpCellPath->find(cell->strSubjectReader)->second.size() - (nCellId - (*it)->id) + 1; 	
+											//nRealId = mpCellPath->find(cell->strOriginReaderName)->second.size() - (nCellId - (*it)->id) + 1; 	
+											if (nCellId == 0)
+											{
+												nRealId = mpCellPath->find(cell->strSubjectReader)->second.size();
+												strReaderName = cell->strSubjectReader;
+											}else if(nCellId > 0){
+												nRealId = nCellId;
+												strReaderName = (*it)->strSubjectReader;
+											}else if(nCellId < 0){
+												nRealId = mpCellPath->find(cell->strSubjectReader)->second.size() - abs(nCellId);
+												strReaderName = cell->strSubjectReader;
+											}
 										}
+										if(first_max == cell_min){	
+											//nRealId = nCellId - mpCellPath->find((*it)->strSubjectReader)->second.size();
+											//nRealId = nCellId - mpCellPath->find((*it)->strOriginReaderName)->second.size();
+											//只存在nCellId>0的情况,但还要区分它是否大于所在分站的总格子数
+											if (nCellId >= mpCellPath->find((*it)->strSubjectReader)->second.size())
+											{
+												nRealId = nCellId - mpCellPath->find(cell->strSubjectReader)->second.size();
+												if (nRealId == 0)
+												{
+													nRealId = 1;
+												}
+												strReaderName = cell->strSubjectReader;
+											}else if(nCellId < mpCellPath->find((*it)->strSubjectReader)->second.size()){
+												nRealId = nCellId;
+												strReaderName = (*it)->strSubjectReader;
+											}
+										}
+										if(first_max == cell_max){
+											//nRealId = (mpCellPath->find(cell->strSubjectReader))->second.size() - (nCellId - ((mpCellPath->find((*it)->strSubjectReader))->second.size() - (*it)->id)) + 1;
+											//nRealId = (mpCellPath->find(cell->strOriginReaderName))->second.size() - (nCellId - ((mpCellPath->find((*it)->strOriginReaderName))->second.size() - (*it)->id)) + 1;
+											if (nCellId >= mpCellPath->find((*it)->strSubjectReader)->second.size())
+											{
+												nRealId = mpCellPath->find(cell->strOriginReaderName)->second.size() - (nCellId - mpCellPath->find((*it)->strSubjectReader)->second.size());
+												strReaderName = cell->strOriginReaderName;
+											}else if(nCellId < mpCellPath->find((*it)->strSubjectReader)->second.size()){
+												nRealId = nCellId;
+												strReaderName = (*it)->strSubjectReader;
+											}
+										}
+										nCellId = nRealId;
+									}else{
+										nCellId = LocateAlgorithm::round(y);
+										//strReaderName = cell->strSubjectReader;
+										strReaderName = cell->strOriginReaderName;
+									}
+									//将新格子的信息除了格子id信息
+									cell = FindCell(strReaderName,nCellId);
+									if (cell)
+									{
+										cell->originId = tmpOriginId;
+										cell->strOriginReaderName = tmpOriginReaderName;
+									}
+								} 
+								else
+								{
+									if (!isAdded)
+									{
+										colourfulCloudsChasingTheMoon(cell,his_cell);
 									}
 								}
 							}
+						}else{
+							//his_cell.push_back(cell);
+							//如果是第一次定位结果,调用以下函数将cell放入到his_cell队列中
+							colourfulCloudsChasingTheMoon(cell,his_cell);
 						}
 					}else{
 						originCellId = 0;
@@ -4387,9 +4473,11 @@ std::shared_ptr<Cell> Card::FindCell(std::string strReaderName,int cellid)
 			cell->left = (*it)->left;
 			cell->bottom = (*it)->bottom;
 			cell->right = (*it)->right;
+			cell->strSubjectReader = (*it)->strSubjectReader;
 			cell->isHasBranch = (*it)->isHasBranch;
 			cell->maxReaderId = (*it)->maxReaderId;
 			cell->minReaderId = (*it)->minReaderId;
+			cell->realId = cellid;
 			break;
 		}
 	}
@@ -5114,10 +5202,6 @@ int Card::SaveCardAlgoData(std::shared_ptr<Cell>& cell)
 	curCellReaderName = cell->strSubjectReader;
 	curCellId = cell->id;
 
-	if (is_algo_first_location)
-	{
-		is_algo_first_location = false;
-	}
 	//更新格子信息
 	cell->nStep = nStep;
 	cell->dataSource = 1;
@@ -5169,68 +5253,31 @@ int Card::SaveCardAlgoData(std::shared_ptr<Cell>& cell)
 		locate_cells.push_back(last_cell);
 	}else
 		return 1;
-	//::PostMessage(pMainWnd,WM_CARD_SEND_JSON,(WPARAM)this,(LPARAM)last_cell.get());
 	mu.unlock();
 
-	if (!is_fit_pos && m_nLastLocateT != 0)
+	if (!is_algo_first_location)
 	{
 		//确保第一次不会进来算速度
 		if (this->x != INVALID_COORDINATE && this->y != INVALID_COORDINATE)
 		{
 			//pos为本次定位坐标,(x,y)为上一次定位坐标
 			double distance = sqrt(pow(pos->cx - this->x,2) + pow(pos->cy - this->y,2))*map_scale;
-			this->mileage = distance;
+			this->mileage = distance/1000.0;
 			int nCounts = ceil(distance/CELL_WIDTH);
 			this->v = nCounts*CELL_WIDTH/(SEND_CELL_INTERVAL/1000.0);
 			this->v*=3.6;
 		}
-	}else{
-		this->v = this->v / 2;
-	}
-
-	if (this->v > 30)
-	{
-		this->v = 25;
 	}
 
 	this->x = pos->cx;
 	this->y = pos->cy;
 	this->z = 0;
 
-	if (m_nLastLocateT != 0 && this->last_locate.x != INVALID_COORDINATE && this->last_locate.y != INVALID_COORDINATE)
-	{
-		if (abs(this->last_locate.x) > 1E-5 || abs(this->last_locate.y) > 1E-5)
-		{
-			//去除采集刚启动,last_locate的坐标为零而导致判断车辆上下行方向错误的问题
-			//车辆上下行确定
-			//3个条件:起点(x1,y1),终点(x2,y2)
-			//1.x1==x2的情况下,y2>y1为下行
-			//2.y1==y2的情况下,x1>x2为下行  
-			//3.x1>x2且y2>y1为下行
-			//其他情况为上行
-			int nStream = 0;
-			if ((this->last_locate.x == this->x && this->y > this->last_locate.y)
-				||(this->last_locate.x > this->x && this->y == this->last_locate.y)
-				||(this->last_locate.x > this->x && this->y > this->last_locate.y))
-			{
-				nStream = DOWN_STREAM;
-			} 
-			else
-			{
-				nStream = UP_STREAM;
-			}
-			this->m_nStream = nStream;
-		}
-	}
-
-	//如果怠速,则速度置为零
-	if (CheckIdleStatus())
+	if (!is_algo_first_location )
 	{
-		this->v = 0;
+		this->m_nStream = GetStream(this->last_locate.x,this->last_locate.y,this->x,this->y);
 	}
 
-	is_fit_pos = pos->is_fit;
-
 	this->last_locate.x = pos->cx;
 	this->last_locate.y = pos->cy;
 	this->last_locate.z = 0;
@@ -5238,6 +5285,11 @@ int Card::SaveCardAlgoData(std::shared_ptr<Cell>& cell)
 	this->m_nLastLocateT = this->m_nCalcSyncNum;
 	this->last_locate.v = this->v;
 
+	if (is_algo_first_location)
+	{
+		is_algo_first_location = false;
+	}
+
 	return 0;
 }
 
@@ -6653,15 +6705,22 @@ int Card::colourfulCloudsChasingTheMoon(std::shared_ptr<Cell> &cell, std::list<s
 							pY[i] = (*it)->id; //跟前者在相同基站之间							
 						}else
 						{
-							int last_min = (*first_cell)->minReaderId; //last_cell_temp对应的最小分站
-							int last_max = (*first_cell)->maxReaderId; //last_cell_temp对应的最大分站
-							int cell_min = (*it)->minReaderId; //cell对应的最小分站
-							int cell_max = (*it)->maxReaderId; //cell对应的最大分站
+							int last_min = (*first_cell)->minReaderId;	//last_cell_temp对应的最小分站
+							int last_max = (*first_cell)->maxReaderId;	//last_cell_temp对应的最大分站
+							int cell_min = (*it)->minReaderId;			//cell对应的最小分站
+							int cell_max = (*it)->maxReaderId;			//cell对应的最大分站
 							if(last_min == cell_min){
-								pY[i] = pY[i - 1] + pY[i - 1] - 1 + (*it)->id; //换基站了	
+								//pY[i] = pY[i - 1] + pY[i - 1] - 1 + (*it)->id; //换基站了	
+								pY[i] = 0 - (*it)->id; 
 							}
 							if(last_min == cell_max){
-								pY[i] = pY[i - 1] + pY[i - 1] - 1 + mpCellPath->find((*it)->strSubjectReader)->second.size() - (*it)->id + 1; //换基站了	
+								//pY[i] = pY[i - 1] + pY[i - 1] - 1 + mpCellPath->find((*it)->strSubjectReader)->second.size() - (*it)->id + 1; //换基站了
+								int nSize = 0;
+								nSize = mpCellPath->find((*it)->strSubjectReader)->second.size();
+								int nDiff = (*it)->id - nSize;
+								float a = nDiff*1.0;
+								pY[i] = a;
+								//pY[i] = (*it)->id - mpCellPath->find((*it)->strSubjectReader)->second.size();
 							}
 							if(last_max == cell_min){
 								pY[i] = mpCellPath->find((*first_cell)->strSubjectReader)->second.size()  + (*it)->id; //换基站了	
@@ -6693,6 +6752,10 @@ int Card::colourfulCloudsChasingTheMoon(std::shared_ptr<Cell> &cell, std::list<s
 				k = vResult.at(0);
 				float b = 0.0;
 				b = vResult.at(1);
+
+				fit_k = k;
+				fit_b = b;
+
 				float Relation = 0.0;
 				Relation = vResult.at(2);
 				//如果是怠速,则当前cell的真实id=idlastcell的真实id
@@ -6707,29 +6770,89 @@ int Card::colourfulCloudsChasingTheMoon(std::shared_ptr<Cell> &cell, std::list<s
 					}
 				}else{
 					std::list<std::shared_ptr<Cell>>::reverse_iterator end_cell = myCellList.rbegin();
-					int realId = floor(pY[0] * k + b); //考虑到有可能跨基站,处理下形成realId
+					//int realId = floor(pY[0] * k + b); //考虑到有可能跨基站,处理下形成realId
+					int realId = floor(pX[4] * k + b);
+					std::string strReaderName = "";
+					std::string tmpOriginReaderName = "";
+					int tmpOriginId = 0;
+					tmpOriginId = cell->originId;
+					tmpOriginReaderName = cell->strOriginReaderName;
 					if ((*first_cell)->strSubjectReader == (*end_cell)->strSubjectReader){
-						cell->realId = realId; //跟前者在相同基站之间							
+							cell->realId = realId; //跟前者在相同基站之间	
+							strReaderName = (*first_cell)->strSubjectReader;
 						}else
 						{
 							//换基站了
 							int first_min = (*first_cell)->minReaderId; //first_cell_temp对应的最小分站
 							int first_max = (*first_cell)->maxReaderId; //first_cell_temp对应的最大分站
-							int cell_min = (*end_cell)->minReaderId; //cell对应的最小分站
-							int cell_max = (*end_cell)->maxReaderId; //cell对应的最大分站
+							int cell_min = (*end_cell)->minReaderId;	//cell对应的最小分站
+							int cell_max = (*end_cell)->maxReaderId;	//cell对应的最大分站
 							if(first_min == cell_min){
-								cell->realId = realId - pY[0]; 	
+								//cell->realId = realId - pY[0]; 	
+								if (realId == 0)
+								{
+									cell->realId = 1;
+									strReaderName = (*end_cell)->strSubjectReader;
+								}else if(realId > 0){
+									cell->realId = realId;
+									strReaderName = (*first_cell)->strSubjectReader;
+								}else{
+									cell->realId = abs(realId);
+									strReaderName = (*end_cell)->strSubjectReader;
+								}
 							}
 							if(first_min == cell_max){
-								cell->realId = mpCellPath->find((*end_cell)->strSubjectReader)->second.size() - (realId - pY[0]) + 1; 	
+								if (realId == 0)
+								{
+									cell->realId = mpCellPath->find((*end_cell)->strSubjectReader)->second.size();
+									strReaderName = (*end_cell)->strSubjectReader;
+								}else if(realId > 0){
+									//cell->realId = mpCellPath->find((*end_cell)->strSubjectReader)->second.size() - (realId - pY[0]) + 1; 
+									cell->realId = realId;
+									strReaderName = (*first_cell)->strSubjectReader;
+								}else{
+									cell->realId = mpCellPath->find((*end_cell)->strSubjectReader)->second.size() + realId;
+									strReaderName = (*end_cell)->strSubjectReader;
+								}
 							}
 							if(first_max == cell_min){
-								cell->realId = realId - (mpCellPath->find((*first_cell)->strSubjectReader)->second.size() - pY[0]); 		
+								//cell->realId = realId - (mpCellPath->find((*first_cell)->strSubjectReader)->second.size() - pY[0]); 	
+								//cell->realId = realId - mpCellPath->find((*first_cell)->strSubjectReader)->second.size();
+								//strReaderName = (*first_cell)->strSubjectReader;
+								if (realId >= mpCellPath->find((*first_cell)->strSubjectReader)->second.size())
+								{
+									cell->realId = realId - mpCellPath->find((*first_cell)->strSubjectReader)->second.size();
+									if (cell->realId == 0)
+									{
+										cell->realId = 1;
+									}
+									strReaderName = (*end_cell)->strSubjectReader;
+								}else{
+									cell->realId = mpCellPath->find((*first_cell)->strSubjectReader)->second.size() - realId;
+									strReaderName = (*first_cell)->strSubjectReader;
+								}
 							}
 							if(first_max == cell_max){
-								cell->realId = (mpCellPath->find((*end_cell)->strSubjectReader))->second.size() - (realId - ((mpCellPath->find((*first_cell)->strSubjectReader))->second.size() - pY[0])) + 1;
+								//cell->realId = (mpCellPath->find((*end_cell)->strSubjectReader))->second.size() - (realId - ((mpCellPath->find((*first_cell)->strSubjectReader))->second.size() - pY[0])) + 1;
+								//strReaderName = (*end_cell)->strSubjectReader;
+								if (realId >= mpCellPath->find((*first_cell)->strSubjectReader)->second.size())
+								{
+									cell->realId = mpCellPath->find((*end_cell)->strSubjectReader)->second.size() - (realId - mpCellPath->find((*first_cell)->strSubjectReader)->second.size());
+									strReaderName = (*end_cell)->strSubjectReader;
+								} 
+								else
+								{
+									cell->realId = realId;
+									strReaderName = (*first_cell)->strSubjectReader;
+								}
 							}
-						}									
+						}	
+						cell = FindCell(strReaderName,cell->realId);
+						if (cell)
+						{
+							cell->originId = tmpOriginId;
+							cell->strOriginReaderName = tmpOriginReaderName;
+						}
 				}
 			}else{
 				cell = nullptr;