Пример #1
0
TEST(SFM_DATA_FILTERS, LargestViewTrackCC)
{
  // Init a scene with 5 Views & poses
  SfM_Data sfm_data;
  init_scene(sfm_data, 5);

  // Fill with some tracks
  //
  //- View 0,1,2 are sharing 3 tracks
  // TrackId 0 -> 0-1-2
  // TrackId 1 -> 0-1-2
  // TrackId 2 -> 0-1-2
  //
  // While view 3-4 are sharing 1 track
  // TrackId 3 -> 3-4

  Observations obs;
  obs[0] = Observation( Vec2(10,20), 0);
  obs[1] = Observation( Vec2(30,10), 1);
  obs[2] = Observation( Vec2(30,10), 1);
  sfm_data.structure[0].obs = obs;
  sfm_data.structure[0].X = Vec3::Random();

  sfm_data.structure[1].obs = obs;
  sfm_data.structure[1].X = Vec3::Random();
  sfm_data.structure[2].obs = obs;
  sfm_data.structure[2].X = Vec3::Random();

  obs.clear();
  obs[3] = Observation( Vec2(10,20), 0);
  obs[4] = Observation( Vec2(10,20), 0);
  sfm_data.structure[3].obs = obs;
  sfm_data.structure[3].X = Vec3::Random();

  // Track of the SfM_Data scene contains two connected component
  // One for view (0,1,2)
  // One for the view (3,4)
  // Test that function to keep the largest one is working
  EXPECT_EQ (4, sfm_data.GetLandmarks().size());
  EXPECT_FALSE (IsTracksOneCC(sfm_data));
  KeepLargestViewCCTracks(sfm_data);
  EXPECT_EQ (3, sfm_data.GetLandmarks().size());
}
Пример #2
0
int YAMRSlave::run_model(Parameters &pars, Observations &obs)
{
	int success = 1;
	//bool isDouble = true;
	//bool forceRadix = true;
	//TemplateFiles tpl_files(isDouble,forceRadix,tplfile_vec,inpfile_vec,par_name_vec);
	//InstructionFiles ins_files(insfile_vec,outfile_vec,obs_name_vec);
	std::vector<double> obs_vec;
	try 
	{
	//	message.str("");
		int ifail;
		int ntpl = tplfile_vec.size();
		int npar = pars.size();
		vector<string> par_name_vec;
		vector<double> par_values;
		for(auto &i : pars)
		{
			par_name_vec.push_back(i.first);
			par_values.push_back(i.second);
		}
		wrttpl_(&ntpl, StringvecFortranCharArray(tplfile_vec, 50).get_prt(),
			StringvecFortranCharArray(inpfile_vec, 50).get_prt(),
			&npar, StringvecFortranCharArray(par_name_vec, 50, pest_utils::TO_LOWER).get_prt(),
			par_values.data(), &ifail);
		if(ifail != 0)
		{
			throw PestError("Error processing template file:" + tpl_err_msg(ifail));
		}
		//tpl_files.writtpl(par_values);

		// update parameter values
		pars.clear();
		for (int i=0; i<npar; ++i)
		{
			pars[par_name_vec[i]] = par_values[i];
		}

		// run model
		for (auto &i : comline_vec)
		{
			ifail = system(i.c_str());
			if(ifail != 0)
		{
			cerr << "Error executing command line: " << i << endl;
			throw PestError("Error executing command line: " + i);
		}
		}
		// process instructio files
		int nins = insfile_vec.size();
		int nobs = obs_name_vec.size();
		std::vector<double> obs_vec;
		obs_vec.resize(nobs, -9999.00);
		readins_(&nins, StringvecFortranCharArray(insfile_vec, 50).get_prt(),
			StringvecFortranCharArray(outfile_vec, 50).get_prt(),
			&nobs, StringvecFortranCharArray(obs_name_vec, 50, pest_utils::TO_LOWER).get_prt(),
			obs_vec.data(), &ifail);
		if(ifail != 0)
		{
			throw PestError("Error processing template file");
		}
		//obs_vec = ins_files.readins();


		// check parameters and observations for inf and nan
		if (std::any_of(par_values.begin(), par_values.end(), OperSys::double_is_invalid))
		{
			throw PestError("Error running model: invalid parameter value returned");
		}
		if (std::any_of(obs_vec.begin(), obs_vec.end(), OperSys::double_is_invalid))
		{
			throw PestError("Error running model: invalid observation value returned");
		}
		// update observation values
		obs.clear();
		for (int i=0; i<nobs; ++i)
		{
			obs[obs_name_vec[i]] = obs_vec[i];
		}

	}
	catch(const std::exception& ex)
	{
		cerr << endl;
		cerr << "   " << ex.what() << endl;
		cerr << "   Aborting model run" << endl << endl;
		success = 0;
	}
	catch(...)
	{
		cerr << "   Error running model" << endl;
		cerr << "   Aborting model run" << endl;
		success = 0;
	}
	return success;
}
Пример #3
0
void RunManagerSerial::run()
{
	int ifail;
	int success_runs = 0;
	int prev_sucess_runs = 0;
	const vector<string> &par_name_vec = file_stor.get_par_name_vec();
	const vector<string> &obs_name_vec = file_stor.get_obs_name_vec();
	int npar = par_name_vec.size();
	int nobs = obs_name_vec.size();
	int ntpl = tplfile_vec.size();
	int nins = insfile_vec.size();
	stringstream message;		
	bool isDouble = true;
	bool forceRadix = true;
	//TemplateFiles tpl_files(isDouble, forceRadix, tplfile_vec, inpfile_vec, par_name_vec);
	//InstructionFiles ins_files(insfile_vec, outfile_vec);
	std::vector<double> obs_vec;
	// This is necessary to support restart as some run many already be complete
	vector<int> run_id_vec;
	int nruns = get_outstanding_run_ids().size();
	while (!(run_id_vec = get_outstanding_run_ids()).empty())
	{
		for (int i_run : run_id_vec)
		{			
			//first delete any existing input and output files			
			for (auto &out_file : outfile_vec)
			{
				if((check_exist_out(out_file)) && (remove(out_file.c_str()) != 0))
					throw PestError("model interface error: Cannot delete existing model output file "+out_file);				
			}
			for (auto &in_file : inpfile_vec)
			{
				if ((check_exist_out(in_file)) && (remove(in_file.c_str()) != 0))
					throw PestError("model interface error: Cannot delete existing model input file " + in_file);
			}
			Observations obs;
			vector<double> par_values;
			Parameters pars;
			file_stor.get_parameters(i_run, pars);						
			try {
				std::cout << string(message.str().size(), '\b');
				message.str("");
				message << "(" << success_runs << "/" << nruns << " runs complete)";
				std::cout << message.str();
				OperSys::chdir(run_dir.c_str());
				for (auto &i : par_name_vec)
				{
					par_values.push_back(pars.get_rec(i));
				}
				if (std::any_of(par_values.begin(), par_values.end(), OperSys::double_is_invalid))
				{
					throw PestError("Error running model: invalid parameter value returned");
				}
				wrttpl_(&ntpl, StringvecFortranCharArray(tplfile_vec, 50).get_prt(),
					StringvecFortranCharArray(inpfile_vec, 50).get_prt(),
					&npar, StringvecFortranCharArray(par_name_vec, 50, pest_utils::TO_LOWER).get_prt(),
					&par_values[0], &ifail);
				if (ifail != 0)
				{
					throw PestError("Error processing template file");
				}								
				for (int i = 0, n_exec = comline_vec.size(); i < n_exec; ++i)
				{
					system(comline_vec[i].c_str());
				}
				obs_vec.resize(nobs, RunStorage::no_data);
				readins_(&nins, StringvecFortranCharArray(insfile_vec, 50).get_prt(),
					StringvecFortranCharArray(outfile_vec, 50).get_prt(),
					&nobs, StringvecFortranCharArray(obs_name_vec, 50, pest_utils::TO_LOWER).get_prt(),
					&obs_vec[0], &ifail);
				if (ifail != 0)
				{
					throw PestError("Error processing instruction file");
				}				
				// check parameters and observations for inf and nan
				if (std::any_of(par_values.begin(), par_values.end(), OperSys::double_is_invalid))
				{
					throw PestError("Error running model: invalid parameter value returned");
				}
				if (std::any_of(obs_vec.begin(), obs_vec.end(), OperSys::double_is_invalid))
				{
					throw PestError("Error running model: invalid observation value returned");
				}

				/*
				// IOPP version
				for (int i = 0, n_exec = comline_vec.size(); i < n_exec; ++i)
				{
				system(comline_vec[i].c_str());
				}
				//pest_utils::thread_flag* tf1(false);
				//pest_utils::thread_flag* tf2(false);
				//w_run_commands(tf1,tf2,comline_vec);
				ins_files.read(obs_name_vec, obs);
				*/

				success_runs += 1;
				
				pars.clear();
				pars.insert(par_name_vec, par_values);
				obs.clear();
				obs.insert(obs_name_vec, obs_vec);								
				file_stor.update_run(i_run, pars, obs);
				
			}
			catch (const std::exception& ex)
			{
				file_stor.update_run_failed(i_run);
				cerr << endl;
				cerr << "  " << ex.what() << endl;
				cerr << "  Aborting model run" << endl << endl;
			}
			catch (...)
			{
				file_stor.update_run_failed(i_run);
				cerr << endl;
				cerr << "  Error running model" << endl;
				cerr << "  Aborting model run" << endl << endl;
			}
		}
	}

	total_runs += success_runs;
	std::cout << string(message.str().size(), '\b');
	message.str("");
	message << "(" << success_runs << "/" << nruns << " runs complete";
	if (prev_sucess_runs > 0)
	{
		message << " and " << prev_sucess_runs << " additional run completed previously";
	}
	message << ")";
	std::cout << message.str();
	if (success_runs < nruns)
	{			cout << endl << endl;
		cout << "WARNING: " << nruns - success_runs << " out of " << nruns << " runs failed" << endl << endl;
	}
	std::cout << endl << endl;
}
Пример #4
0
void RunManagerGenie::run()
{
	int nexec = comline_vec.size();
	const vector<string> &par_name_vec = file_stor.get_par_name_vec();
	const vector<string> &obs_name_vec = file_stor.get_obs_name_vec();
	int npar = par_name_vec.size();
	int nobs = obs_name_vec.size();
	int ntpl = tplfile_vec.size();
	int nins = insfile_vec.size();

	stringstream apar;
	stringstream aobs;
	stringstream execnames;
	stringstream tplfle;
	stringstream infle;
	stringstream insfle;
	stringstream outfle;

	 vector<double> par_val;
	 vector<double> obs_val;
	 vector<int> ifail;

	// This is necessary to support restart as some run many already be complete
	vector<int> run_id_vec = get_outstanding_run_ids();
	int nruns = run_id_vec.size();

	 par_val.clear();
	 obs_val.resize(nruns*nobs);
	 ifail.resize(nruns);
	for (int i_run : run_id_vec)
	{
	     Parameters tmp_pars;
	     file_stor.get_parameters(i_run, tmp_pars);
		 vector<double> tmp_vec = tmp_pars.get_data_vec(par_name_vec);
		 par_val.insert(par_val.end(), tmp_vec.begin(), tmp_vec.end());
	}

	vector<string> par_name_vec_lwr = par_name_vec;
	for (auto &ipar : par_name_vec_lwr)
	{
		lower_ip(ipar);
	}
	vector<string> obs_name_vec_lwr = obs_name_vec;
	for (auto &iobs : obs_name_vec_lwr)
	{
		lower_ip(iobs);
	}
	std::copy(par_name_vec_lwr.begin(), par_name_vec_lwr.end(),std::ostream_iterator<std::string>(apar,"\n"));
	std::copy(obs_name_vec_lwr.begin(), obs_name_vec_lwr.end(),std::ostream_iterator<std::string>(aobs,"\n"));
	std::copy(comline_vec.begin(), comline_vec.end(),std::ostream_iterator<std::string>(execnames,"\n"));
	std::copy(tplfile_vec.begin(), tplfile_vec.end(),std::ostream_iterator<std::string>(tplfle,"\n"));
	std::copy(inpfile_vec.begin(), inpfile_vec.end(),std::ostream_iterator<std::string>(infle,"\n"));
	std::copy(insfile_vec.begin(), insfile_vec.end(),std::ostream_iterator<std::string>(insfle,"\n"));
	std::copy(outfile_vec.begin(), outfile_vec.end(),std::ostream_iterator<std::string>(outfle,"\n"));

	#ifdef OS_WIN
	GENIE_INTERFACE(&nruns, &nexec, String2CharPtr(execnames.str()).get_char_ptr(), &npar, &nobs,
	String2CharPtr(apar.str()).get_char_ptr(), String2CharPtr(aobs.str()).get_char_ptr(),
					&par_val[0], &obs_val[0], &ntpl, &nins, String2CharPtr(tplfle.str()).get_char_ptr(),
					String2CharPtr(infle.str()).get_char_ptr(), String2CharPtr(insfle.str()).get_char_ptr(),
					String2CharPtr(outfle.str()).get_char_ptr(),
					String2CharPtr(host).get_char_ptr(), String2CharPtr(id).get_char_ptr(), &ifail[0]);
	#endif
	#ifdef OS_LINUX
	throw(PestError("Error: Genie run manager is not supported under linux"));
	#endif

	total_runs += nruns;
	Parameters pars;
	Observations obs;
	for (int i=0; i<nruns; ++i)
	{
		if (ifail[i] == 0)
		{
			int run_id = run_id_vec[i];
			pars.clear();
			vector<double> i_par_vec(par_val.begin() + i*npar, par_val.begin() + (i + 1)*npar);
			pars.insert(par_name_vec, i_par_vec);
			obs.clear();
			vector<double> i_obs_vec(obs_val.begin() + i*nobs, obs_val.begin() + (i + 1)*nobs);
			obs.insert(obs_name_vec, i_obs_vec);
			file_stor.update_run(run_id, pars, obs);
		}
		else
		{
			file_stor.set_run_nfailed(i, max_n_failure);
		}
	}
}