示例#1
0
bool DataCenter::TDTread(std::string filename)
{
   laydata::TEDfile tempin(filename.c_str(), &_TEDLIB);
   if (!tempin.status()) return false;

   try
   {
      tempin.read(TARGETDB_LIB);
   }
   catch (EXPTNreadTDT)
   {
      tempin.closeF();
      tempin.cleanup();
      return false;
   }
   tempin.closeF();
   _TEDLIB.deleteDB();//Erase existing data
   _tedfilename = filename;
   _neversaved = false;
   _TEDLIB.setDB(static_cast<laydata::tdtdesign*>(tempin.design()));
   _TEDLIB()->assign_properties(_properties);
   // Update Canvas scale
   _properties.setUU(_TEDLIB()->UU());
   return true;
}
示例#2
0
bool DataCenter::TDTwrite(const char* filename)
{
   if (filename)  _tedfilename = filename;
   laydata::TEDfile tempin(_tedfilename, &_TEDLIB);
   _neversaved = false;
   return true;
}
示例#3
0
bool DataCenter::TDTwrite(const char* filename, TpdTime* timeCreated,
                          TpdTime* timeSaved)
{
   std::string news;
   // File created time stamp must match exactly, otherwise it means
   // that we're saving not exactly the same file that is requested
   if ((NULL != timeCreated) && (timeCreated->stdCTime() != _TEDDB->created()))
   {
      news = "time stamp \"Project created \" doesn't match. File save aborted";
      tell_log(console::MT_ERROR,news);
      return false;
   }
   if (NULL != timeSaved)
   {
      if (_TEDDB->lastUpdated() < timeSaved->stdCTime())
      {
         news = "Database is older or doesn't contain new data, File save operation ignored";
         tell_log(console::MT_WARNING,news);
         _neversaved = false;
         return false;
      }
      else if (_TEDDB->lastUpdated() > timeSaved->stdCTime())
         wxGetApp().set_ignoreOnRecovery(false);
      else
      {
         wxGetApp().set_ignoreOnRecovery(false);
         return false;
      }
   }
   if (filename)  _tedfilename = filename;
   laydata::TEDfile tempin(_TEDDB, _tedfilename);
   _neversaved = false;
   return true;
}
示例#4
0
bool DataCenter::TDTcheckread(const std::string filename,
    const TpdTime& timeCreated, const TpdTime& timeSaved, bool& start_ignoring)
{
   bool retval = false;
   start_ignoring = false;
   laydata::TEDfile tempin(filename.c_str(), TEDLIB());
   if (!tempin.status()) return retval;

   std::string news = "Project created: ";
   TpdTime timec(tempin.created()); news += timec();
   tell_log(console::MT_INFO,news);
   news = "Last updated: ";
   TpdTime timeu(tempin.lastUpdated()); news += timeu();
   tell_log(console::MT_INFO,news);
   // File created time stamp must match exactly, otherwise it means
   // that we're reading not exactly the same file that is requested
   if (timeCreated != timec)
   {
      news = "time stamp \"Project created \" doesn't match";
      tell_log(console::MT_ERROR,news);
   }
   if (timeu.stdCTime() < timeSaved.stdCTime())
   {
      news = "time stamp \"Last updated \" is too old.";
      tell_log(console::MT_ERROR,news);
   }
   else if (timeu.stdCTime() > timeSaved.stdCTime())
   {
      news = "time stamp \"Last updated \" is is newer than requested.";
      news +="Some of the following commands will be ignored";
      tell_log(console::MT_WARNING,news);
      //Start ignoring
      start_ignoring = true;
      retval = true;
   }
   else
   {
      retval = true;
   }
   tempin.closeF();
   return retval;
} 
示例#5
0
int DataCenter::TDTloadlib(std::string filename)
{
   laydata::TEDfile tempin(filename.c_str(), &_TEDLIB);
   if (!tempin.status()) return -1;
   int libRef = _TEDLIB.getLastLibRefNo();
   try
   {
      tempin.read(libRef);
   }
   catch (EXPTNreadTDT)
   {
      tempin.closeF();
      tempin.cleanup();
      return -1;
   }
   tempin.closeF();
   _TEDLIB.addlibrary(tempin.design(), libRef);
   // Relink everything
   _TEDLIB.relink();
   return libRef;
}
示例#6
0
void LpSolver::populatebyrow (CplexConverter& cplexConverter, 
	IloModel model, IloNumVarArray x, IloRangeArray c)
{
	IloEnv env = model.getEnv();
	// CAPITAL LETTERS MEAN I NEED YOUR HELP, here is help 

	// IloExpr cost(env);
	
	// Create Variables
	// cout << "size of var: " << cplexConverter.variables.size() << endl;
	for (int i = 0; i < cplexConverter.variables.size(); ++i){
		IloNumVar iloVar(env, 0.0, cplexConverter.capacities[i], IloNumVar::Int);
		// cout << iloVar << endl;
		x.add(iloVar);
	}

	//Capacity Constraints
	for (auto &it : cplexConverter.atomicIdToVarIdDict){
		IloExpr t(env);
		// cout << "adding constraint ";
		for (int j = 0; j < it.second.size(); j++){
			// cout << "x[" << it.second[j] << "] + ";
			t += x[it.second[j]];
		}
		// cout << endl;
		c.add(t <= cplexConverter.graph->atomicEdges[it.first]->capacity);
		// cout << c << endl;
		t.end();
	}

	// other constraints
	for (auto nodePair : cplexConverter.graph->nodes){

		// For all nodes
		Node* n = nodePair.second;

		if(n == cplexConverter.src){

			// source constraints
			// IloExpr inFlow(env);
			IloExpr outFlow(env);	
			for(auto &atoIn : n->atomicEdge_in){
				int aeId = atoIn.second->atomicEdgeId;
				for (int j = 0; j < cplexConverter.atomicIdToVarIdDict[aeId].size(); j++){
					// var Id
					int vId = cplexConverter.atomicIdToVarIdDict[aeId][j];
					outFlow += x[vId];
					// cost += cplexConverter.graph->atomicEdges[cplexConverter.variables[vId].atomicEdgeId]->interest_rate * x[vId];
				}
			}
			for (auto &atoOut : n->atomicEdge_out){
				int aeId = atoOut.second->atomicEdgeId;
				for (int j = 0; j < cplexConverter.atomicIdToVarIdDict[aeId].size(); j++){
					// var Id
					int vId = cplexConverter.atomicIdToVarIdDict[aeId][j];
					// inFlow += x[vId];
					c.add(x[vId] == 0);
					// cost -= cplexConverter.graph->atomicEdges[cplexConverter.variables[vId].atomicEdgeId]->interest_rate * x[vId];
				}
			}

			c.add(outFlow == cplexConverter.request);
			// inFlow.end();
			outFlow.end();

		} else if(n == cplexConverter.dest){

			// destination constraints
			IloExpr inFlow(env);
			// IloExpr outFlow(env);
			for(auto &atoIn : n->atomicEdge_in){
				int aeId = atoIn.second->atomicEdgeId;
				for (int j = 0; j < cplexConverter.atomicIdToVarIdDict[aeId].size(); j++){
					// var Id
					int vId = cplexConverter.atomicIdToVarIdDict[aeId][j];
					// outFlow += x[vId];
					c.add(x[vId] == 0);
				}
			}
			for (auto &atoOut : n->atomicEdge_out){
				int aeId = atoOut.second->atomicEdgeId;
				for (int j = 0; j < cplexConverter.atomicIdToVarIdDict[aeId].size(); j++){
					// var Id
					int vId = cplexConverter.atomicIdToVarIdDict[aeId][j];
					inFlow += x[vId];
				}
			}

			c.add(inFlow == cplexConverter.request);
			inFlow.end();
			// outFlow.end();

		} else {

			// Monotonicity Constraints
			for (int i = 0; i < credNetConstants.totalIrs.size(); ++i){
				IloExpr tempin(env);
				IloExpr tempout(env);

				for (auto &atoIn : n->atomicEdge_in){
					int aeId = atoIn.second->atomicEdgeId;
					for (int j = 0; j < cplexConverter.atomicIdToVarIdDict[aeId].size(); j++){

						// var Id
						int vId = cplexConverter.atomicIdToVarIdDict[aeId][j];
						if (cplexConverter.variables[vId].interest_rate <= credNetConstants.totalIrs[i]){
							tempout += x[vId];
						}
					}
				}
				for (auto &atoOut : n->atomicEdge_out){
					int aeId = atoOut.second->atomicEdgeId;
					for (int j = 0; j < cplexConverter.atomicIdToVarIdDict[aeId].size(); j++){

						// var Id
						int vId = cplexConverter.atomicIdToVarIdDict[aeId][j];
						if (cplexConverter.variables[vId].interest_rate <= credNetConstants.totalIrs[i]){
							tempin += x[vId];
						}
					}
				}

				c.add(tempout - tempin >= 0);
				tempout.end();
				tempin.end();
			}

			//Flow Constraints
			IloExpr inFlow(env);
			IloExpr outFlow(env);	
			for(auto &atoIn : n->atomicEdge_in){
				int aeId = atoIn.second->atomicEdgeId;
				for (int j = 0; j < cplexConverter.atomicIdToVarIdDict[aeId].size(); j++){
					// var Id
					int vId = cplexConverter.atomicIdToVarIdDict[aeId][j];
					outFlow += x[vId];
				}
			}
			for (auto &atoOut : n->atomicEdge_out){
				int aeId = atoOut.second->atomicEdgeId;
				for (int j = 0; j < cplexConverter.atomicIdToVarIdDict[aeId].size(); j++){
					// var Id
					int vId = cplexConverter.atomicIdToVarIdDict[aeId][j];
					inFlow += x[vId];
				}
			}

			c.add(inFlow - outFlow == 0);
			inFlow.end();
			outFlow.end();

		}

	}


	model.add(c);
	// model.add(IloMinimize(env, cost));
	// model.add(IloMaximize(env,cost));  //option to minimize cost
	// cost.end();

}  // END populatebyrow
示例#7
0
bool DataCenter::TDTread(std::string filename, TpdTime* timeCreated,
                         TpdTime* timeSaved)
{
   laydata::TEDfile tempin(filename.c_str());
   if (!tempin.status()) return false;

   std::string news = "Project created: ";
   TpdTime timec(tempin.created()); news += timec();
   tell_log(console::MT_INFO,news);
   news = "Last updated: ";
   TpdTime timeu(tempin.lastUpdated()); news += timeu();
   tell_log(console::MT_INFO,news);
   // File created time stamp must match exactly, otherwise it means
   // that we're reading not exactly the same file that is requested
   if ((NULL != timeCreated) && (*timeCreated != timec))
   {
      news = "time stamp \"Project created \" doesn't match";
      tell_log(console::MT_ERROR,news);
      tempin.closeF();
      return false;
   }
   if (NULL != timeSaved)
   {
      if (timeu.stdCTime() < timeSaved->stdCTime())
      {
         news = "time stamp \"Last updated \" is too old.";
         tell_log(console::MT_ERROR,news);
         tempin.closeF();
         return false;
      }
      else if (timeu.stdCTime() > timeSaved->stdCTime())
      {
         news = "time stamp \"Last updated \" is is newer than requested.";
         news +="Some of the following commands will be ignored";
         tell_log(console::MT_WARNING,news);
         //Start ignoring
         wxGetApp().set_ignoreOnRecovery(true);
      }
   }
   try
   {
      tempin.read();
   }
   catch (EXPTNreadTDT)
   {
      tempin.closeF();
      tempin.cleanup();
      return false;
   }
   tempin.closeF();
   delete _TEDDB;//Erase existing data
   _tedfilename = filename;
   _neversaved = false;
   _TEDDB = tempin.design();
   _TEDDB->btreeAddMember    = &browsers::treeAddMember;
   _TEDDB->btreeRemoveMember = &browsers::treeRemoveMember;
   // get the hierarchy
   browsers::addTDTtab(_TEDDB->name(), _TEDDB->hiertree());
   // Update Canvas scale
   Properties->setUU(_TEDDB->UU());
   return true;
}