示例#1
0
文件: MPSRead.cpp 项目: Tian-Xie/HELP
int MPS_ReadFile()
{
	n_Row = 0;
	n_Col = 0;
	Hash_Row.Init(MAX_ROWS, 999983);
	Hash_Col.Init(MAX_COLS, 999983);
	Obj_Row = 0;
	n_Element = 0;
	V_Cost_Intercept = 0;
	
	printf("ReadMPSFile BEGIN\n");
	Fin = fopen(Filename, "r");
	MPS_ReadLine();
	
	MPS_NAME();
	MPS_ROWS();
	MPS_COLUMNS();
	MPS_RHS();
	MPS_RANGES();
	MPS_BOUNDS();
	MPS_ENDATA();
	
	fclose(Fin);
	Hash_Row.Release();
	Hash_Col.Release();
	printf("ReadMPSFile END\n");
	return 0;
}
示例#2
0
文件: MPSRead.cpp 项目: Tian-Xie/HELP
void MPS_COLUMNS()
{
	if (strncmp(Buf, "COLUMNS", 7))
		CheckError(1, "MPS_COLUMNS: Expected COLUMNS!");
	printf("    COLUMNS SECTION\n");
	ColItemNo = 0;
	while (1)
	{
		ColItemNo ++;
		MPS_ReadLine();

		if (Buf[0] != ' ') // End of COLUMNS
			break;
		unsigned long long ColHash = MPS_HashCode(Buf + CARD_POS[0]);
		int ColID = Hash_Col.Find(ColHash);
		if (ColID == HASH_NOT_FOUND)
		{
			Hash_Col.Insert(ColHash, n_Col);
			ColID = n_Col;
			V_Cost[n_Col] = 0.0;
			V_Matrix_Col_Head[n_Col] = -1;
			n_Col ++;
		}

		int CurCardLen = strlen(Buf);
		for (int ip = 1; ip <= 3 && CARD_POS[ip] < CurCardLen; ip += 2)
		{
			unsigned long long RowHash = MPS_HashCode(Buf + CARD_POS[ip]);
			int RowID = Hash_Row.Find(RowHash);
			if (RowID == HASH_NOT_FOUND)
			{
				printf("        Warning: Row Name Not Found, HashCode = %llu, Ignored.\n", RowHash);
				continue;
			}
			double RCValue = atof(Buf + CARD_POS[ip + 1]);
			if (RowID == HASH_OBJECTIVE) // Objective, Minimization
			{
				V_Cost[ColID] = RCValue;
				continue;
			}
			if (fabs(RCValue) < Input_Tolerance)
			{
				printf("        Warning: Zero Element Found, %.10lf, Ignored.\n", RCValue);
				continue;
			}
			// Cannot check duplicate element
			V_Matrix_Row[n_Element] = RowID;
			V_Matrix_Value[n_Element] = RCValue;
			V_Matrix_Col_Next[n_Element] = V_Matrix_Col_Head[ColID];
			V_Matrix_Col_Head[ColID] = n_Element;
			n_Element ++;
		}
	}
	printf("        %d Columns and %d Elements Read (Objective Row Excluded)\n", n_Col, n_Element);
}
示例#3
0
int main()
{
	FILE * pr, *pbg, *pen;
	char bgword[20];
	char enword[20];
	int s;
	//Ttable obj;
	//TDihotTable obj;
	//TBinTree obj;
	THashTable obj;

	pr = fopen("data.txt", "r");
	if (!pr)
	{
		printf("file cannnot be opened-1");
		getch();
		return 0;
	}
	pbg = fopen("data_bg.txt", "r");
	if (!pbg)
	{
		printf("file cannnot be opened-2");
		getch();
		return 0;
	}

	pen = fopen("data_en.txt", "a");
	if (!pen)
	{
		printf("file cannnot be opened-3");
		getch();
		return 0;
	}

	while (!feof(pr))
	{
		fscanf(pr, "%s", bgword);
		fscanf(pr, "%s", enword);
		obj.add(bgword, enword);
	}
	obj.print();

	while (!feof(pbg))
	{
		fscanf(pbg, "%s", bgword);
		int k = obj.search(bgword, enword, s);
		if (k != -1)
			fprintf(pen, "%s\n", enword);

	}

	_getch();
	return 0;
}
示例#4
0
文件: MPSRead.cpp 项目: Tian-Xie/HELP
void MPS_BOUNDS()
{
	for (int i = 0; i < n_Col; i ++)
	{
		V_LB[i] = Var_Lower_Bound;
		V_UB[i] = Var_Upper_Bound;
	}
	
	if (strncmp(Buf, "BOUNDS", 6))
	{
		printf("    NULL BOUNDS Section!\n");
		return;
	}
	printf("    BOUNDS SECTION\n");
	unsigned long long Enabled_BOUNDS_Hash = MPS_HashCode(Enabled_BOUNDS);
	int n_BOUNDS = 0;
	while (1)
	{
		MPS_ReadLine();
		if (Buf[0] != ' ') // End of BOUNDS
			break;
		if (Enabled_BOUNDS_Hash != 0 && Enabled_BOUNDS_Hash != MPS_HashCode(Buf + CARD_POS[0]))
			continue;
		
		unsigned long long ColHash = MPS_HashCode(Buf + CARD_POS[1]);
		int ColID = Hash_Col.Find(ColHash);
		if (ColID == HASH_NOT_FOUND)
		{
			printf("        Warning: Column Name Not Found, HashCode = %llu, Ignored.\n", ColHash);
			continue;
		}
		double Value = 0.0;
		if (strlen(Buf) > 24)
			Value = atof(Buf + CARD_POS[2]);

		if (Buf[1] == 'L' && Buf[2] == 'O' && Buf[3] == ' ')
			V_LB[ColID] = Value;
		else if (Buf[1] == 'U' && Buf[2] == 'P' && Buf[3] == ' ')
			V_UB[ColID] = Value;
		else if (Buf[1] == 'F' && Buf[2] == 'X' && Buf[3] == ' ')
			V_LB[ColID] = V_UB[ColID] = Value;
		else if (Buf[1] == 'F' && Buf[2] == 'R' && Buf[3] == ' ')
		{
			V_LB[ColID] = -MaxPositive;
			V_UB[ColID] = MaxPositive;
		}
		else if (Buf[1] == 'M' && Buf[2] == 'I' && Buf[3] == ' ')
		{
			V_LB[ColID] = -MaxPositive;
			V_UB[ColID] = Value;
		}
		else if (Buf[1] == 'P' && Buf[2] == 'L' && Buf[3] == ' ')
		{
			V_LB[ColID] = Value;
			V_UB[ColID] = MaxPositive;
		}
		n_BOUNDS ++;
	}
	printf("        %d BOUNDS Read\n", n_BOUNDS);
}
示例#5
0
void TClassInfo::Register()
{
#if _DEBUG
  // reentrance guard
  static int entry = 0;
#endif

  THashTable * classTable;

  if (!sm_classTable)
  {
    // keep the hash local initially, reentrance is possible
    classTable = new THashTable();
    classTable->reserve(50);
  }
  else
  {
    // guard against reentrance once the global has been created
    assert(++entry == 1 || "TClassInfo::Register() reentrance");
    classTable = sm_classTable;
  }

  assert(classTable->Get(m_classId) == nullptr);

  classTable->Put(m_classId, this);

  // if we're using a local hash we need to try to make it global
  if (sm_classTable != classTable)
  {
    if (!sm_classTable)
    {
      // make the hash global
      sm_classTable = classTable;
    }
    else
    {
      // the gobal hash has already been created by a reentrant call,
      // so delete the local hash and try again
      delete classTable;
      Register();
    }
  }

#if _DEBUG
  entry = 0;
#endif
}
示例#6
0
文件: MPSRead.cpp 项目: Tian-Xie/HELP
void MPS_ROWS()
{
	if (strncmp(Buf, "ROWS", 4))
		CheckError(1, "MPS_ROWS: Expected ROWS!");
	printf("    ROWS SECTION\n");
	while (1)
	{
		MPS_ReadLine();
		if (Buf[0] != ' ') // End of ROWS
			break;
		char Type = toupper(Buf[1]);
		if (Type == ' ')
			Type = toupper(Buf[2]);
		if (Type != 'N' && Type != 'E' && Type != 'G' && Type != 'L')
		{
			printf("        Warning: Unknown Type: \"%c\", Ignored.\n", Type);
			continue;
		}
		unsigned long long Hash = MPS_HashCode(Buf + CARD_POS[0]);
		if (Type == 'N')
		{
			if (Obj_Row)
			{
				printf("        Warning: Duplicate Objective Row, Ignored.\n");
				continue;
			}
			Obj_Row = Hash; // Store Objective Row's Hash Value
			Hash_Row.Insert(Hash, HASH_OBJECTIVE); // Objective
			continue;
		}
		if (Hash_Row.Insert(Hash, n_Row) == HASH_INSERT_FOUND)
		{
			printf("        Warning: Duplicate Row Name, HashCode = %llu, Ignored.\n", Hash);
			continue;
		}
		Row_Type[n_Row] = Type;
		V_RHS[n_Row] = 0.0;
		n_Row ++;
	}
	printf("        %d Rows Read (Objective Row Excluded)\n", n_Row);
	if (! Obj_Row)
		CheckError(1, "MPS_ROWS: No Objective Row!");
}
示例#7
0
void RunTest() {
   int value;

   THashTable map;
   map.Create(20);
   map["AAKDKDV"] = 1;
   map["VDDADV"]  = 2;
   map["MIK2ADD"] = 3;
   map["MIK3ADD"] = 4;
   map["MIK4ADD"] = 5;
   map["MIKEA5D"] = 6;
   map["MIKEAD1"] = 8 ;
   map["M0KEADD"] = 9;

   if ( map.Lookup("M0KEADD",value) ) {
        printf("value = %d\n", value);
   }
   return ;
}
示例#8
0
文件: MPSRead.cpp 项目: Tian-Xie/HELP
void MPS_RHS()
{
	if (strncmp(Buf, "RHS", 3))
	{
		printf("    NULL RHS Section!\n");
		return;
	}
	printf("    RHS SECTION\n");
	unsigned long long Enabled_RHS_Hash = MPS_HashCode(Enabled_RHS);
	int n_RHS = 0;
	while (1)
	{
		MPS_ReadLine();
		if (Buf[0] != ' ') // End of RHS
			break;
		if (Enabled_RHS_Hash != 0 && Enabled_RHS_Hash != MPS_HashCode(Buf + CARD_POS[0]))
			continue;
		
		int CurCardLen = strlen(Buf);
		for (int ip = 1; ip <= 3 && CARD_POS[ip] < CurCardLen; ip += 2)
		{
			unsigned long long RowHash = MPS_HashCode(Buf + CARD_POS[ip]);
			int RowID = Hash_Row.Find(RowHash);
			if (RowID == HASH_NOT_FOUND)
			{
				printf("        Warning: Row Name Not Found, HashCode = %llu, Ignored.\n", RowHash);
				continue;
			}
			double RCValue = atof(Buf + CARD_POS[ip + 1]);
			if (RowID == HASH_OBJECTIVE) // Objective, Minimization
			{
				printf("        Warning: Row Name Cannot Be Cost Row, Ignored.\n");
				continue;
			}
			if (fabs(RCValue) < Input_Tolerance)
			{
				printf("        Warning: Zero Element Found, %.10lf, Ignored.\n", RCValue);
				continue;
			}
			V_RHS[RowID] = RCValue;
			n_RHS ++;
		}
	}
	printf("        %d RHS Read\n", n_RHS);
}
示例#9
0
文件: MPSRead.cpp 项目: Tian-Xie/HELP
void MPS_RANGES()
{
	for (int i = 0; i < n_Row; i ++)
		V_RHS_r[i] = V_RHS[i];
	if (strncmp(Buf, "RANGES", 6))
	{
		printf("    NULL RANGES Section!\n");
		return;
	}
	printf("    RANGES SECTION\n");
	unsigned long long Enabled_RANGES_Hash = MPS_HashCode(Enabled_RANGES);
	int n_RANGES = 0;
	while (1)
	{
		MPS_ReadLine();
		if (Buf[0] != ' ') // End of RANGES
			break;
		if (Enabled_RANGES_Hash != 0 && Enabled_RANGES_Hash != MPS_HashCode(Buf + CARD_POS[0]))
			continue;
		
		int CurCardLen = strlen(Buf);
		for (int ip = 1; ip <= 3 && CARD_POS[ip] < CurCardLen; ip += 2)
		{
			unsigned long long RowHash = MPS_HashCode(Buf + CARD_POS[ip]);
			int RowID = Hash_Row.Find(RowHash);
			if (RowID == HASH_NOT_FOUND)
			{
				printf("        Warning: Row Name Not Found, HashCode = %llu, Ignored.\n", RowHash);
				continue;
			}
			double Value = atof(Buf + CARD_POS[ip + 1]);
			if (RowID == HASH_OBJECTIVE) // Objective, Minimization
			{
				printf("        Warning: Row Name Cannot Be Cost Row, Ignored.\n");
				continue;
			}
			if (fabs(Value) < Input_Tolerance)
			{
				printf("        Warning: Zero Element Found, %.10lf, Ignored.\n", Value);
				continue;
			}
			// TODO, Follow lpguide
			if (Row_Type[RowID] == 'E')
			{
				if (Value < 0)
					V_RHS_r[RowID] += Value;
				else
					V_RHS[RowID] += Value;
			}
			else if (Row_Type[RowID] == 'L')
				V_RHS_r[RowID] -= fabs(Value);
			else if (Row_Type[RowID] == 'G')
				V_RHS[RowID] += fabs(Value);
			else
			{
				printf("        Warning: Duplicate RANGES, HashCode = %llu, Ignored.\n", RowHash);
				continue;
			}
			Row_Type[RowID] = 'R'; // Ranged
		}
	}
	printf("        %d RANGES Read\n", n_RANGES);
}
示例#10
0
Bool_t MakeCosmicTriggersEntry(const char *fileName, const char* cdbUri)
{
  const char* macroname = "MakeCosmicTriggersEntry.C";

  if (gSystem->AccessPathName(fileName)) {
    Error(macroname,Form("file (%s) not found", fileName));
    return kFALSE;
  }

  ifstream *file = new ifstream(fileName);
  if (!*file) {
    Error(macroname,Form("Error opening file (%s) !",fileName));
    file->close();
    delete file;
    return kFALSE;
  }

  THashTable *table = new THashTable();
  table->SetName("List of defined cosmic triggers");

  TString strLine;
  while (strLine.ReadLine(*file)) {

    if (strLine.BeginsWith("#")) continue;

    strLine.ReplaceAll(" ","");
    strLine.ReplaceAll("\t","");
    if (strLine.IsNull()) continue;

    TObjString *obj = new TObjString(strLine.Data());
    table->Add(obj);
  }

  file->close();
  delete file;


  // create OCDB storage
  TString Storage(cdbUri);
  if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
    Error(macroname,"STORAGE variable set to %s is not valid. Exiting\n",Storage.Data());
    return kFALSE;
  }
  AliCDBManager* cdb = AliCDBManager::Instance();
  AliCDBStorage* storage = cdb->GetStorage(Storage.Data());
  if(!storage){
    Error(macroname,"Unable to open storage %s\n",Storage.Data());
    return kFALSE;
  }

  AliCDBMetaData* md = new AliCDBMetaData();
  md->SetResponsible("Federico Antinori");
  md->SetComment("List of the defined cosmic triggers. It is used in order to steer the reconstruction, namely in the selection of the proper event specie. It is maintained and updated by the trigger coordinator.");
  // Get root and AliRoot versions and set them in the metadata
  const char* rootv = gROOT->GetVersion();
  TString av(ALIROOT_VERSION);
  TString revnum(ALIROOT_REVISION);
  av+=" - revision: ";
  av+=revnum;
  md->SetAliRootVersion(av.Data());

  AliCDBId id("GRP/Calib/CosmicTriggers",0,AliCDBRunRange::Infinity());
  Info(macroname,"Saving the list of defined cosmic triggers in the OCDB storage \"%s\"",Storage.Data());
  storage->Put(table,id,md);

  table->Delete();
  delete table;

  return kTRUE;
}
int runGetMissingDictionaries()
{
   // Method to assert the dictionaries.

   TClass* myClass = TClass::GetClass("TestClass");
   if (myClass->HasDictionary())
      Error("TClass::HasDictionary", "The class %s does not have a dictionary.", "TestClass");

   THashTable expectedResult;
   // Hard coded expected results.
   expectedResult.Add(TClass::GetClass("NoDictClass"));
   expectedResult.Add(TClass::GetClass("TestClass"));
   expectedResult.Add(TClass::GetClass("MemberHidden"));
   expectedResult.Add(TClass::GetClass("Tmplt<Tmplt<NoDictClass*> >"));
   expectedResult.Add(TClass::GetClass("Tmplt<int>"));
   expectedResult.Add(TClass::GetClass("Member"));
   expectedResult.Add(TClass::GetClass("Tmplt<Member>"));
   expectedResult.Add(TClass::GetClass("Tmplt<Base>"));
   expectedResult.Add(TClass::GetClass("Outer<Double32_t>"));
   expectedResult.Add(TClass::GetClass("Tmplt<TmpParam>"));
   expectedResult.Add(TClass::GetClass("Tmplt<Tmplt<TmpTmpParam> >"));
   expectedResult.Add(TClass::GetClass("Tmplt<Tmplt<Tmplt<ExtraTmp> > >"));
   expectedResult.Add(TClass::GetClass("ParamList<ParamL1,ParamL2>"));
   expectedResult.Add(TClass::GetClass("TypedefExample"));
   expectedResult.Add(TClass::GetClass("BasicTests::TestAll"));

   cerr<<"No recursion:"<<endl; // Write on the same stream of the errors below
   THashTable missingDictClassesNoRecursion;
   // Assert GetMissingDictionaries without recursion.
   myClass->GetMissingDictionaries(missingDictClassesNoRecursion, false);
   //missingDictClassesNoRecursion.Print();
   if (!missingDictClassesNoRecursion.IsEmpty()) {
      if (missingDictClassesNoRecursion.GetEntries() != expectedResult.GetEntries()) {
         Error("TClass::GetMissingClassDictionaries", "The set of classes with missing dictionaries does not contain the correct number of elements (expected: %d got %d).",expectedResult.GetEntries(),missingDictClassesNoRecursion.GetEntries());
      }
      TIterator* it = missingDictClassesNoRecursion.MakeIterator();
      TClass* cl = 0;
      while ((cl = (TClass*)it->Next())) {
         if (!expectedResult.FindObject(cl)) {
            Error("TCling::GetMissingDictionaries", "Class %s is not in the expected set.", cl->GetName());
         }
      }
      it = expectedResult.MakeIterator();
      while ((cl = (TClass*)it->Next())) {
         if (!missingDictClassesNoRecursion.FindObject(cl)) {
            Error("TCling::GetMissingDictionaries", "Class %s with no dictionaries is not in the set.", cl->GetName());
         }
      }
   } else {
      Error("TClass::GetMissingClassDictionaries", "The set of missing classes is not created");
   }


   // Assert GetMissingDictionaries with recursion.
   // Hard code expected results with recursion.
   expectedResult.Add(TClass::GetClass("ArrayTry"));
   expectedResult.Add(TClass::GetClass("NoA"));
   expectedResult.Add(TClass::GetClass("vector<Tmplt<NoDictClass*> >"));
   expectedResult.Add(TClass::GetClass("Tmplt<NoDictClass*>"));
   expectedResult.Add(TClass::GetClass("vector<Member>"));
   expectedResult.Add(TClass::GetClass("Base"));
   expectedResult.Add(TClass::GetClass("vector<Base>"));
   expectedResult.Add(TClass::GetClass("Inner<Double32_t>"));
   expectedResult.Add(TClass::GetClass("TmpParam"));
   expectedResult.Add(TClass::GetClass("TmpTmpParam"));
   expectedResult.Add(TClass::GetClass("Tmplt<TmpTmpParam>"));
   expectedResult.Add(TClass::GetClass("ExtraTmp"));
   expectedResult.Add(TClass::GetClass("Tmplt<ExtraTmp>"));
   expectedResult.Add(TClass::GetClass("Tmplt<Tmplt<ExtraTmp> >"));
   expectedResult.Add(TClass::GetClass("vector<Tmplt<Tmplt<ExtraTmp> > >"));
   expectedResult.Add(TClass::GetClass("vector<NoDictClass*> "));
   expectedResult.Add(TClass::GetClass("vector<TmpTmpParam>"));
   expectedResult.Add(TClass::GetClass("vector<Tmplt<ExtraTmp> >"));
   expectedResult.Add(TClass::GetClass("vector<ExtraTmp> "));
   expectedResult.Add(TClass::GetClass("vector<Tmplt<TmpTmpParam> >"));
   expectedResult.Add(TClass::GetClass("vector<TmpParam>"));
   expectedResult.Add(TClass::GetClass("vector<Double32_t>"));
   expectedResult.Add(TClass::GetClass("ParamL1"));
   expectedResult.Add(TClass::GetClass("ParamL2"));
   expectedResult.Add(TClass::GetClass("vector<ParamL2*>"));
   expectedResult.Add(TClass::GetClass("BasicTests::NoDictTypdefs"));
   expectedResult.Add(TClass::GetClass("BasicTests::NoDict"));
   expectedResult.Add(TClass::GetClass("BasicTests::HasVecDoubleTD32"));
   expectedResult.Add(TClass::GetClass("BasicTests::HasVecDouble32"));
   expectedResult.Add(TClass::GetClass("map<unsigned short,Double32_t>"));

   cerr<<"With recursion:"<<endl; // Write on the same stream of the errors below
   THashTable missingDictClassesRecursion;
   myClass->GetMissingDictionaries(missingDictClassesRecursion, true);
   //missingDictClassesRecursion.Print();
   if (!missingDictClassesRecursion.IsEmpty()) {
      if (missingDictClassesRecursion.GetEntries() != expectedResult.GetEntries()) {
         Error("TClass::GetMissingClassDictionaries", "The set of classes with missing dictionaries does not contain the correct number of elements (expected: %d got %d).",expectedResult.GetEntries(),missingDictClassesRecursion.GetEntries());
//         expectedResult.ls();
//         missingDictClassesRecursion.ls();
      }
      TIterator* it = missingDictClassesRecursion.MakeIterator();
      TClass* cl = 0;
      while ((cl = (TClass*)it->Next())) {
         if (!expectedResult.FindObject(cl)) {
            Error("TCling::GetMissingDictionaries", "Class %s is not in the expected set.", cl->GetName());
         }
      }
      it = expectedResult.MakeIterator();
      while ((cl = (TClass*)it->Next())) {
         if (!missingDictClassesRecursion.FindObject(cl)) {
            Error("TCling::GetMissingDictionaries", "Class %s with no dictionaries is not in the set.", cl->GetName());
         }
      }
   } else {
      Error("TClass::GetMissingClassDictionaries", "The set of missing classes is not created");
   }

  return 0;
}