Chain get_chain(Hierarchy h) { do { if (h == Hierarchy()) { return Chain(); } if (Chain::get_is_setup(h)) { return Chain(h); } } while ((h = h.get_parent())); return Chain(); }
//TSP -> NN -> Generations( g, ForkJoin ( n, SA -> 2-OPT ) ) -> TSP' void Pipeline1(tsp_class& tsp_instance, unsigned int number_of_tasks, unsigned int number_of_generations) { #pragma region "PipelineConfiguration" auto a = Args<General_args_type>(make_General_args(number_of_generations, number_of_tasks)); auto sa = Args<SA_args_type>(make_SA_args(1000.0, 0.00001, 0.999, 400)); auto aco = Args<ACO_args_type>(); auto ga = Args<GA_args_type>(); const char* pipeline_description = "TSP -> NN -> Generations( g, ForkJoin ( n, SA -> 2-OPT ) ) -> TSP'"; display_args(pipeline_description, a, sa, aco, ga); auto g = a[0].number_of_iterations_or_generations; auto n = a[0].number_of_tasks_in_parallel; auto _TSP = TSP(just(tsp_instance)); auto _DisplayInput = Display("TSP INPUT", DisplayFlags::All); auto _NN = Measure(NN(), Display("NEAREST NEIGHBOUR", DisplayFlags::EmitMathematicaGraphPlot)); auto _SA_2OPT = Chain(SA(sa[0].initial_temperature, sa[0].stopping_criteria_temperature, sa[0].decreasing_factor, sa[0].monte_carlo_steps), _2OPT()); auto _ForkJoin = [](unsigned int n, TSP::transformer_type map_fun){ return Measure(ForkJoin(n, map_fun)); }; auto _DisplayOutput = Display("TSP OUTPUT", DisplayFlags::EmitMathematicaGraphPlot); #pragma endregion //TSP -> NN -> Generations( g, ForkJoin ( n, SA -> 2-OPT ) ) -> TSP' auto result = _TSP .map(_DisplayInput) .map(_NN) .map(Generations(g, _ForkJoin(n, _SA_2OPT))) .map(_DisplayOutput); }
//TSP -> NN -> Generations( g, ForkJoin ( n, GA -> 2-OPT ) ) -> TSP' void Pipeline2(tsp_class& tsp_instance, unsigned int number_of_tasks, unsigned int number_of_generations) { #pragma region "PipelineConfiguration" auto a = Args<General_args_type>(make_General_args(number_of_generations, number_of_tasks)); auto sa = Args<SA_args_type>(); auto aco = Args<ACO_args_type>(); auto ga = Args<GA_args_type>(make_GA_args(1000, 10, 5, 50000, 10, 0.9)); const char* pipeline_description = "TSP -> NN -> Generations( g, ForkJoin ( n, GA -> 2-OPT ) ) -> TSP'"; display_args(pipeline_description, a, sa, aco, ga); auto g = a[0].number_of_iterations_or_generations; auto n = a[0].number_of_tasks_in_parallel; auto _TSP = TSP(just(tsp_instance)); auto _DisplayInput = Display("TSP INPUT", DisplayFlags::All); auto _NN = Measure(NN(), Display("NEAREST NEIGHBOUR", DisplayFlags::EmitMathematicaGraphPlot)); auto _GA_2OPT = Chain(GA(ga[0].population_size, ga[0].mutation_percentage, ga[0].group_size, ga[0].number_of_generations, ga[0].nearby_cities, ga[0].nearby_cities_percentage), _2OPT()); auto _ForkJoin = [](unsigned int n, TSP::transformer_type map_fun){ return Measure(ForkJoin(n, map_fun)); }; auto _DisplayOutput = Display("TSP OUTPUT", DisplayFlags::EmitMathematicaGraphPlot); #pragma endregion //TSP -> NN -> Generations( g, ForkJoin ( n, GA -> 2-OPT ) ) -> TSP' auto result = _TSP .map(_DisplayInput) .map(_NN) .map(Generations(g, _ForkJoin(n, _GA_2OPT))) .map(_DisplayOutput); }
void lMuDst() { gROOT->LoadMacro("bfc.C"); TString Chain("StEvent,CMuDst,nodefault"); bfc(-2,Chain,0,0,0); // gROOT->LoadMacro("FitP_t.h+"); gSystem->Load("libEG"); // gSystem->Load("libStKFVertex"); }
virtual void SetUp() { V = -0.6; lL = Lead(1.2, 2.0, -0.4, -0.4, 300, 0, 0); T1 = "-0.4, 0.0; 0.0, -0.4"; B1 = Insulator(5.4, 5.4, -0.4, -0.4, 5, 0, 0, V); T2 = "-0.4, 0.0; 0.0, -0.4"; lR = Lead(1.2, 2.0, -0.4, -0.4, 300, M_PI/2, V); wire = Chain(lL, T1, B1, T2, lR); }
CTestResource::CTestResource(LPCTSTR pszHostPort, LPCTSTR target, LPCTSTR pszDownloadPort, int nBaud, LPCTSTR pszResetString): m_strReset(pszResetString), m_bInUse(false), m_nBaud(nBaud), m_strPort(pszDownloadPort), m_bLocked(false), m_Target(target) { CeCosSocket::ParseHostPort(pszHostPort,m_strHost,m_nPort); VTRACE(_T("@@@ Created resource %08x %s\n"),(unsigned int)this,(LPCTSTR)Image()); Chain(); }
Hierarchy get_next_residue(Residue rd) { // only handle simple case so far Hierarchy p = rd.get_parent(); /*if (!p.get_as_chain()) { IMP_NOT_IMPLEMENTED("get_next_residue() only handles the simple case" << " so far. Complain about it."); }*/ IMP_USAGE_CHECK(Chain::get_is_setup(p), "Parent of residue must be a chain. It is not."); Hierarchy r = get_residue(Chain(p), rd.get_index() + 1); return r; }
//TSP -> NN -> Generations( g, ForkJoin ( n, ACO -> 2-OPT ) ) -> TSP' void Pipeline3(tsp_class& tsp_instance, unsigned int number_of_tasks, unsigned int number_of_generations) { #pragma region "PipelineConfiguration" auto a = Args<General_args_type>(make_General_args(number_of_generations, number_of_tasks)); auto sa = Args<SA_args_type>(); auto ga = Args<GA_args_type>(); const int aco_iterations = static_cast<int>(tsp_instance.cities.size() * 100); const ants_type::size_type number_of_ants = tsp_instance.cities.size(); const double BASE_PHEROMONE = 1.0f / static_cast<double>(tsp_instance.cities.size()); const double ALPHA = 1.0; const double BETA = 1.0; const double RHO = 0.9; const double QVAL = 70; auto aco = Args<ACO_args_type>(make_ACO_args(aco_iterations, number_of_ants, BASE_PHEROMONE, ALPHA, BETA, RHO, QVAL)); const char* pipeline_description = "TSP -> NN -> Generations( g, ForkJoin ( n, ACO -> 2-OPT ) ) -> TSP'"; display_args(pipeline_description, a, sa, aco, ga); auto g = a[0].number_of_iterations_or_generations; auto n = a[0].number_of_tasks_in_parallel; auto _TSP = TSP(just(tsp_instance)); auto _DisplayInput = Display("TSP INPUT", DisplayFlags::All); auto _NN = Measure(NN(), Display("NEAREST NEIGHBOUR", DisplayFlags::EmitMathematicaGraphPlot)); auto _ACO_2OPT = Chain(ACO(aco[0].aco_iterations, aco[0].number_of_ants, aco[0].base_pheromone, aco[0].favor_pheromone_level_over_distance, aco[0].favor_distance_over_pheromone_level, aco[0].value_for_intensification_and_evaporation, aco[0].pheronome_distribution), _2OPT()); auto _ForkJoin = [](unsigned int n, TSP::transformer_type map_fun){ return Measure(ForkJoin(n, map_fun)); }; auto _DisplayOutput = Display("TSP OUTPUT", DisplayFlags::EmitMathematicaGraphPlot); #pragma endregion //TSP -> NN -> Generations( g, ForkJoin ( n, ACO -> 2-OPT ) ) -> TSP' auto result = _TSP .map(_DisplayInput) .map(_NN) .map(Generations(g, _ForkJoin(n, _ACO_2OPT))) .map(_DisplayOutput); }
Hierarchy create_simplified_along_backbone(Hierarchy in, int num_res, bool keep_detailed) { Hierarchies chains= get_by_type(in, CHAIN_TYPE); if (chains.size() > 1) { Hierarchy root= Hierarchy::setup_particle(new Particle(in->get_model(), in->get_name())); for (unsigned int i=0; i< chains.size(); ++i) { Chain chain(chains[i].get_particle()); root.add_child(create_simplified_along_backbone(chain, num_res)); } return root; } else if (chains.size()==1) { // make sure to cast it to chain to get the right overload return create_simplified_along_backbone(Chain(chains[0]), num_res, keep_detailed); } else { IMP_THROW("No chains to simplify", ValueException); } }
ChainConfig(size_t n, const ParameterConfig& initialParamConf, const Proposal* propFunc = nullptr) : // in case of parallel tempering, setup more than one chain fPtChains( n, Chain() ), // prepare parameter configurations fDynamicParamConfigs( n, initialParamConf ), // clone the default proposal function fProposalFunctions( n ) { LOG_ASSERT( n > 0, "A Metropolis chain set requires at least 1 chain" << " (and corresponding beta value)."); if (propFunc) for (auto& p : fProposalFunctions) p.reset( propFunc->Clone() ); if (n > 0) { fNProposedSwaps.assign( n-1, 0 ); fNAcceptedSwaps.assign( n-1, 0 ); } }
PDBStructureType PDBModel:: FindAny(const char *str, PDBChain **c, PDBResidue **r, PDBAtom **a, PDBStructureType maxlevel) const { // Check str if (!str) return PDB_MODEL; if (strlen(str) < 1) return PDB_MODEL; // Construct chain name char chain_name[4]; chain_name[0] = str[0]; if (chain_name[0] == '_') chain_name[0] = ' '; chain_name[1] = '\0'; // Find chain from name PDBChain *result = NULL; for (int i = 0; i < NChains(); i++) { PDBChain *chain = Chain(i); if (!strcmp(chain->Name(), chain_name)) { result = chain; break; } } // Fill return values and consider matches at deeper levels PDBStructureType level = PDB_MODEL; if (result) { level = PDB_CHAIN; if (c) *c = result; const char *strp = (str[1] == '-') ? &str[2] : NULL; if (strp && *strp && (maxlevel > level)) { level = result->FindAny(strp, r, a, maxlevel); } } // Return level of match return level; }
Hierarchy get_previous_residue(Residue rd) { // only handle simple case so far Hierarchy p = rd.get_parent(); Hierarchy r = get_residue(Chain(p), rd.get_index() - 1); return r; }
void Dynacoe::Clock::OnDraw() { if (!GetHost() || IsExpired()) return; float ratio = lastDuration < 0 ? 1.f : GetTimeLeft() / float (lastDuration); std::string data = (Chain() << ratio); EmitEvent("clock-draw"); }
std::string Dynacoe::Clock::GetInfo() { return (Chain() << "Time Left: " << GetTimeLeft() << " ms"); }
int main(int argc, char **argv) { if (argc != 2) { std::cout << argv[0] << ": wanted-exponent\n"; return 0; } int want_exponent = std::stoi(std::string(argv[1])); std::stack<Chain> queue; queue.push(Chain()); int binary_exponentiation_count = -1; int log2w = -1; std::string s; for (int j = want_exponent; j != 0; j >>= 1) { s += std::to_string(j & 1); binary_exponentiation_count += (j & 1); binary_exponentiation_count++; log2w++; } binary_exponentiation_count--; std::reverse(s.begin(), s.end()); std::cout << "Exponent: " << want_exponent << " " << s << "b\n"; int best = binary_exponentiation_count; while (!queue.empty()) { // Chain top = queue.front(); Chain top = queue.top(); queue.pop(); // std::cout << top.getCurrentOutput() << " " << top.getChainLength() << "\n"; if (top.getChainLength() <= static_cast<std::size_t>(best)) { if (top.getCurrentOutput() == want_exponent) { std::vector<ChainOperation> v = top.getOperations(); best = top.getChainLength(); for (auto op : v) { std::cout << op << " "; } std::cout << " x = x**" << std::setw(4) << std::left << top.getCurrentInput() << " Y = x**" << top.getCurrentOutput() << "\n"; } else { const int in = top.getCurrentInput(); const int out = top.getCurrentOutput(); const int max = (in > out)?(in):(out); if (max >= want_exponent) { continue; } // how many squarings would it take int log2m = -1; { unsigned int b = max; while (b >>= 1) { log2m++; } } const int steps = (log2w - log2m); const int totalSteps = top.getChainLength() + steps - 1; if (totalSteps <= best) { Chain ii_i = Chain(top); ii_i.advance(ChainOperation::InputInput_StoreInput); Chain ii_o = Chain(top); ii_o.advance(ChainOperation::InputInput_StoreOutput); Chain io_i = Chain(top); io_i.advance(ChainOperation::InputOutput_StoreInput); Chain io_o = Chain(top); io_o.advance(ChainOperation::InputOutput_StoreOutput); Chain oo_i = Chain(top); oo_i.advance(ChainOperation::OutputOutput_StoreInput); Chain oo_o = Chain(top); oo_o.advance(ChainOperation::OutputOutput_StoreOutput); if (ii_i.getCurrentInput() != in || ii_i.getCurrentOutput() != out) { queue.push(ii_i); } if (io_i.getCurrentInput() != in || io_i.getCurrentOutput() != out) { queue.push(io_i); } if (oo_i.getCurrentInput() != in || oo_i.getCurrentOutput() != out) { queue.push(oo_i); } if (ii_o.getCurrentInput() != in || ii_o.getCurrentOutput() != out) { queue.push(ii_o); } if (io_o.getCurrentInput() != in || io_o.getCurrentOutput() != out) { queue.push(io_o); } if (oo_o.getCurrentInput() != in || oo_o.getCurrentOutput() != out) { queue.push(oo_o); } } } } } std::cout << "Best length is " << best << ", binary exponentiation is " << binary_exponentiation_count << " for exponent " << want_exponent << ".\n"; std::cout << best << '\n'; return 0; }
void WreckingBall::Init(){ chainMovementSpeed = 20.0f; D3DXMatrixRotationYawPitchRoll(&rotationMatrix, 0.0f, 0.0f, 0.0f); D3DXMatrixTranslation(&translationMatrix, 0.0f, 5.0f, 0.0f); D3D10_INPUT_ELEMENT_DESC layout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, // pos { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, sizeof(D3DXVECTOR3), D3D10_INPUT_PER_VERTEX_DATA, 0 }, // normal { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 2*sizeof(D3DXVECTOR3), D3D10_INPUT_PER_VERTEX_DATA, 0 }, // dimensions }; this->SetMaterialInfo(0.600672f, 0.668533f); wreckingBallEffect = Helpers::CustomEffect("SphereEffect.fx", "SphereTechnique", CUSTOM_EFFECT_TYPE_PIXEL | CUSTOM_EFFECT_TYPE_VERTEX, layout, 3); wreckingBallEffect.AddVariable("World"); wreckingBallEffect.AddVariable("View"); wreckingBallEffect.AddVariable("Projection"); // image taken from http://www.cgtextures.com/getfile.php/ConcreteRough0075_1_S.jpg?id=38616&s=s&PHPSESSID=fb96f672ea0d7aff54fd54fe3f539e00 wreckingBallEffect.AddTexture("tex", "Textures\\WreckingBall.jpg"); wreckingBallEffect.AddVariable("LightPos"); wreckingBallEffect.AddVariable("AmbientColor"); wreckingBallEffect.AddVariable("CameraPos"); wreckingBallEffect.AddVariable("LightDirection"); wreckingBallEffect.AddVariable("A"); wreckingBallEffect.AddVariable("B"); wreckingBallEffect.AddVariable("rhoOverPi"); wreckingBallEffect.AddVariable("LightColor"); wreckingBallEffect.SetFloatVector("AmbientColor", Helpers::Globals::AppLight.GetAmbientColor()); wreckingBallEffect.SetFloatVector("LightPos", Helpers::Globals::AppLight.GetPosition()); wreckingBallEffect.SetFloatVector("LightDirection", Helpers::Globals::AppLight.GetDirection()); wreckingBallEffect.SetFloat("A", this->A); wreckingBallEffect.SetFloat("B", this->B); wreckingBallEffect.SetFloat("rhoOverPi", this->rhoOverPi); wreckingBallEffect.SetFloatVector("LightColor", Helpers::Globals::AppLight.GetColor()); // image taken from http://www.cgtextures.com/getfile.php/ConcreteRough0075_1_S.jpg?id=38616&s=s&PHPSESSID=fb96f672ea0d7aff54fd54fe3f539e00 wreckingBallEffect.SetTexture("tex", "Textures\\WreckingBall.jpg"); D3D10_INPUT_ELEMENT_DESC depthLayout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, // pos }; depthEffect = Helpers::CustomEffect("SphereEffect.fx", "SphereDepthTechnique", CUSTOM_EFFECT_TYPE_PIXEL | CUSTOM_EFFECT_TYPE_VERTEX, depthLayout, 1); depthEffect.AddVariable("World"); depthEffect.AddVariable("View"); depthEffect.AddVariable("Projection"); depthEffect.SetMatrix("Projection", Helpers::Globals::AppCamera.Projection()); sphere = Sphere(); sphere.init(radius, 30, 30); sphere.SetPosition(0.0f, 10.0f, -20.0f); this->chain = Chain(); this->chain.Init(sphere.GetPositionVector() + D3DXVECTOR3(0.0f, radius, 0.0f), sphere.GetPositionVector() + D3DXVECTOR3(0.0f, 20.0f + radius, 0.0f), 4); PhysicsWrapper::AddWreckingBall(this); }
void makeTPlots(const Char_t *tag = ""){//"dEdx") { TString FileN(gDirectory->GetName()); gInterpreter->ProcessLine(".L Chain.C"); TChain *theChain = Chain(); TString macro(".L "); const Char_t *T = gSystem->Which(gROOT->GetMacroPath(),"T.C"); macro += T; delete [] T; macro += "+"; gInterpreter->ProcessLine(macro); // gInterpreter->ProcessLine(".L T.C+"); TT t(theChain); #if 1 TString Out = gSystem->DirName(FileN); cout << Out; TString Dir = gSystem->DirName(Out); // Out.ReplaceAll(Dir,""); if (Out.BeginsWith("/")) Out = Out.Data()+1; #else TString Out = gSystem->BaseName(FileN); Out.ReplaceAll(".root",""); #endif Out.ReplaceAll("/","_"); // if (FileN.Contains("6073006_raw") Out += "R06"; // if (FileN.Contains("6073023_raw") Out += "R23"; Out += "Plots"; Out += tag; TString Tag(tag); if (Tag.Contains("G14G",TString::kIgnoreCase) || Tag.Contains("G24G",TString::kIgnoreCase) || Tag.Contains("G34G",TString::kIgnoreCase) || Tag.Contains("G44G",TString::kIgnoreCase)) { t.SetuMinMax(2.5, 2.9); Out += "_u_2.5-2.9"; // Out += "_u_2.5-2.9_v_0-2.8"; // t.SetvMinMax(0.0, 2.8); } if (Tag.Contains("G15G",TString::kIgnoreCase)) { t.SetuMinMax(2.0, 2.5); Out += "_u_2.0-2.5"; // Out += "_u_2.5-2.9_v_0-2.8"; // t.SetvMinMax(0.0, 2.8); } if (Tag.Contains("G21G",TString::kIgnoreCase)) { t.SetVertexZCut(2.0); // cm from z = 0 } if (Tag.Contains("G22G",TString::kIgnoreCase)) { t.SetDipCut(0.9); // pT < DipCut*p } if (Tag.Contains("NoW",TString::kIgnoreCase)) { t.SetNoWafers(); } if (Tag.Contains("BL",TString::kIgnoreCase)) { t.SetLaddersInGlobal(kTRUE); } if (Tag.Contains("ssd",TString::kIgnoreCase)) { t.SetSsd(kTRUE); } if (Tag.Contains("svt",TString::kIgnoreCase)) { t.SetSvt(kTRUE); } if (Tag.Contains("east",TString::kIgnoreCase)) { if (Tag.Contains("fareast",TString::kIgnoreCase)) t.SetEastWest(3); else t.SetEastWest(1); } else { if (Tag.Contains("west",TString::kIgnoreCase)) { if (Tag.Contains("farwest",TString::kIgnoreCase)) t.SetEastWest(4); else t.SetEastWest(2); } } if (Tag.Contains("global",TString::kIgnoreCase)) { t.UseGlobal(); } if (Tag.Contains("local",TString::kIgnoreCase)) { t.UseLocal(); } if (Tag.Contains("dEdx",TString::kIgnoreCase)) { t.SetdEdxCut(4.e-6,40.); } // t.SetRCut(1.0); t.SetRCut(0.5); t.SetMinNoFitPoints(25); Out += "NFP25"; Out += Form("rCut%3.1fcm",t.GetRCut()); Out += ".root"; cout << " ===> " << Out << endl; t.SetOutFileName(Out); t.Loop(0); }