Exemple #1
0
 char* c_str() { return _c_str(); }
//---------------------------------------------------------------------------
void TAlmas3ProbSetGlobal::Init(void)
{//инициализация набора вероятностей
	if(m_bInit == false)
	{
		EnterCriticalSection(&m_InitCS);
		if(m_bInit == false)
		{
		 TProbKeyVec vPK;
		 int nType;
		 //Application->HideHint()
		 //
		 Screen->Cursor = crHourGlass;


		 AnsiString strAll, str1;
		 AnsiString szFilename;
		 szFilename = GetProgramPath()+INTERFACE_ID;
		 szFilename += ".cfg";

		 TProbKey nKey, nKey2;

		 int i=0;
		 if(FileExists(szFilename) == true)
		 {
		  FILE *pFile = fopen(_c_str(szFilename),"r");
		  if(pFile != NULL)
		  {
		   char szVal[256];
		   int Key;
		   while(fgets(szVal, sizeof(szVal), pFile))
		   {
			str1 = szVal;
			str1 = str1.Trim();
			Key = StrToInt(str1);
			nKey = Key;
			vPK.push_back(nKey);
		   }
		   fclose(pFile);
		   bool bChk = true;
		   bool bChk2 = true;
		   m_Key2ToKeyMap.clear();
		   int nPkSize = vPK.size();
		   //int nKey2ToKeyMapSize = m_Key2ToKeyMap.size();
		   for(i = 0; (i < nPkSize) && bChk; i++)
		   {
			nKey = vPK[i];
			bChk2 = false;
			nKey2 = RemoveLeftFromKey2( nKey );
			if(nKey2 == nKey)
			{//нет избыточности
			 nKey2 = CanonateKey2(nKey);
			 if(nKey2 == nKey)
			 {//правильно отсортирован
			  bChk2 = true;
			 }
			}
			if(bChk2 != true)
			{
			 bChk = false;
			}
			//nKey2ToKeyMapSize = m_Key2ToKeyMap.size();
		   }
		   if(bChk == false)
		   {
			vPK.clear();
		   }
		  }
		 }

		 if(vPK.size()==0)
		 {
		  m_Key2ToKeyMap.clear();
		  TProbKey nMaxKey = Adg2Base(2,2)*Adg2State;
		  TProbKey nKey, nKey2;

		  for(nKey = 0; nKey < nMaxKey; nKey++)
		  {
		   nKey2 = RemoveLeftFromKey2( nKey );
		   if(nKey2 == nKey)
		   {//нет избыточности
			nKey2 = CanonateKey2(nKey);
			if(nKey2 == nKey)
			{//правильно отсортирован
			 vPK.push_back(nKey);//добавляем в мап
			}
		   }
		  }

		  //сохранить конфигурацию в файл
		  FILE *pFile = fopen(_c_str(szFilename),"w+");
		  if(pFile != NULL)
		  {
		   for(UINT i = 0; i < vPK.size(); i++)
		   {
			str1=IntToStr((int)(vPK[i]))+"\n";
			fputs(_c_str(str1), pFile);
		   }
		   fclose(pFile);
		  }
		 }

		 TAlmas3ProbSetKey k1,k2;
		 //k1.fill(2468447);
		 //k2.fill(2468495);
		 //k1.fill(189012);//22. (s1, v0; s0, v0)x1 - 189012
		 k1.fill(14);//22. (s1, v0; s0, v0)x1 - 189012

		 TKey2ToKeyMap::iterator itr;
		 vPK.clear();
		 bool bTest = false;
		 //bTest = true;
		 //AnsiString strAll, str1;
		 //int i=0;
		 i=0;
		 for(itr = m_Key2ToKeyMap.begin(); itr != m_Key2ToKeyMap.end(); itr++)
		 {
		  vPK.push_back(itr->second);
		  if(bTest)
		  {
		   k1.fill2(itr->second);
		   GetProbNameFromKey2(itr->second, nType, i, str1);//имя вероятности
		   if(bTest)
		   {
			strAll += str1 + " k2:" +IntToStr((int)itr->first)+"\r\n";
		   }
		  }
		  i++;
		 }

		 if(bTest)
		 {
		  str1 = INTERFACE_ID;
		  str1 += ".txt";

		  FILE *pFile = fopen(_c_str(str1),"w+b");
		  if(pFile != NULL)
		  {
		   fwrite(_c_str(strAll), strAll.Length(),1,pFile);
		   fclose(pFile);
		  }
		 }

		 m_nAllNumProbality = vPK.size();
		 m_pstrProbName = new AnsiString[m_nAllNumProbality];
		 m_pdDefaultProbArr = new double[m_nAllNumProbality];

		 double TypeProb[3];
		 TypeProb[0] = pow(10, -(0)*3);
		 TypeProb[1] = pow(10, -(1)*3);
		 TypeProb[2] = pow(10, -(2)*3);
		 m_PiKeyMap.clear();
		 for(i=0; i < m_nAllNumProbality; i++)
		 {
		  nKey = vPK[i];
		  m_PiKeyMap[nKey] = (TProbIndex)i;
		  //nType = GetTypeFromKey2(nKey);
		  GetProbNameFromKey2(nKey, nType, i, m_pstrProbName[i]);//имя вероятности
		  if(nType> 0 && nType < 4)
		   m_pdDefaultProbArr[i] = TypeProb[nType-1];//значение вероятности по умолчанию
		  else
		   nType /= 0;
		 }
		 Screen->Cursor = crDefault;

		 m_bInit = true;
		}
		LeaveCriticalSection(&m_InitCS);
	}
}
Exemple #3
0
//---------------------------------------------------------------------------
AnsiString TAtomShema::ToStr2(void)
{//изобразить в виде строки
	AnsiString strRet;

	//long nLayer3Spacing = 1;
	//long nLayer2Spacing = (nLayer3Spacing)*3;
	//long nLayer1Spacing = (nLayer2Spacing)*3;
	//long nLayer0Spacing = (nLayer1Spacing)*4;


	const int nCount = 4;
	long nLayerSpacing[nCount];
	AnsiString strLayerFmt[nCount];
	AnsiString strLayer[nCount];
	AnsiString strTmp;

	int i, j, k;
	nLayerSpacing[nCount-1] = 1;
	for(i = nCount-2; i >= 0; i--)
	{
	 nLayerSpacing[i] = (nLayerSpacing[i+1])*(3 + (i==0?1:0));
	}
	for(i = 0; i < nCount; i++)
	{
	 if(nLayerSpacing[i] == 0)
		strLayerFmt[i].sprintf("%%d");
	 else
		strLayerFmt[i].sprintf("%%%dd", nLayerSpacing[i]+1);
	}
	int l=0;
	strLayer[l].sprintf(_c_str(strLayerFmt[l]), GetBit(GetIndex0LevAdj()));
	if(m_nMaxLayer > l)
	for(i = 0; i < 4; i++)
	{
	 l=1;
	 strRet += strTmp.sprintf("(%d:%d",i+1, GetBit(GetIndex1LevAdj(i)));
	 strLayer[l] +=  strTmp.sprintf(_c_str(strLayerFmt[l]), GetBit(GetIndex1LevAdj(i)));
	 if(m_nMaxLayer > l)
	 {
	  strRet += strTmp.sprintf("[");
	  for(j = 0; j < 3; j++)
	  {
	   l=2;
	   strRet += strTmp.sprintf("%d",GetBit(GetIndex2LevAdj(i,j)));
	   strLayer[l] +=  strTmp.sprintf(_c_str(strLayerFmt[l]), GetBit(GetIndex2LevAdj(i,j)));
	   if(m_nMaxLayer > l)
	   {
		strRet += strTmp.sprintf("{");
		for(k = 0; k < 3; k++)
		{
		 l=3;
		 strRet += strTmp.sprintf("%d",GetBit(GetIndex3LevAdj(i,j,k)));
		 strLayer[l] +=  strTmp.sprintf(_c_str(strLayerFmt[l]), GetBit(GetIndex3LevAdj(i,j,k)));
		}
		strRet += strTmp.sprintf("}");
		}
	   }
	   strRet += strTmp.sprintf("]");
	  }
	 strRet += strTmp.sprintf(")");
	}

	strTmp = "";
	for(i = 0; i < nCount; i++)
	{
	 if (strTmp.Length() > 0)
	 {
	  strTmp += "\r\n";
	 }
	 strTmp += strLayer[i];

	 if(i == m_nMaxLayer)
	 {
	  if (strTmp.Length() > 0)
	  {
	   strTmp += "\r\n";
	  }
	  strTmp += "----------------------------------";
	 }
	}
	return strRet;
}