void alg2_decommon_n(Term a2) { List l1; int cnum,cden; Term t; l1=CompoundArgN(a2,5); if(is_empty_list(l1)) { SetCompoundArg(a2,2,0); return; } t=ConsumeCompoundArg(a2,2); cnum=IntegerValue(CompoundArg1(t)); cden=IntegerValue(CompoundArg2(t)); FreeAtomic(t); while(!is_empty_list(l1)) { Term t; int c1,c2,c3; c1=cnum*IntegerValue(CompoundArg1(ListFirst(l1))); c2=cden; c3=gcf(c1,c2); c1/=c3; c2/=c3; t=MakeCompound2(OPR_DIV,NewInteger(c1),NewInteger(c2)); SetCompoundArg(ListFirst(l1),1,t); l1=ListTail(l1); } }
static Term l2expr(List l, int n) { List l1; Term t, res=0; Atom pw; if(CalcOutput) pw=OPR_POW; else pw=OPR_POW; if(l==0) return NewInteger(n); if(n>1 || n<-1) res=NewInteger(n); else { t=ListFirst(l); if(CompoundArg2(t)==NewInteger(1)) res=CompoundArg1(t); else if(CompoundArg2(t)==NewInteger(-1)) res=MakeCompound2(OPR_DIV,NewInteger(1),CompoundArg1(t)); else if(IntegerValue(CompoundArg2(t))>1) res=MakeCompound2(pw,CompoundArg1(t),CompoundArg2(t)); else res=MakeCompound2(OPR_DIV,NewInteger(1), MakeCompound2(pw,CompoundArg1(t), NewInteger(-IntegerValue(CompoundArg2(t))))); if(n<0) res=MakeCompound1(OPR_MINUS,res); l=ListTail(l); } for(l1=l;l1;l1=ListTail(l1)) { t=ListFirst(l1); if(CompoundArg2(t)==NewInteger(1)) res=MakeCompound2(OPR_MLT,res,CompoundArg1(t)); else if(CompoundArg2(t)==NewInteger(-1)) res=MakeCompound2(OPR_DIV,res,CompoundArg1(t)); else if(IntegerValue(CompoundArg2(t))>1) res=MakeCompound2(OPR_MLT,res, MakeCompound2(pw,CompoundArg1(t),CompoundArg2(t))); else res=MakeCompound2(OPR_DIV,res, MakeCompound2(pw,CompoundArg1(t), NewInteger(-IntegerValue(CompoundArg2(t))))); } return res; }
void alg2_recommon_n(Term a2) { List m2l,l,l1,nl; int cnum,n,d; m2l=CompoundArgN(a2,5); nl=NewList(); l=m2l; if(is_empty_list(l)) return; while(!is_empty_list(l)) { nl=AppendLast(nl,CompoundArg1(ListFirst(l))); l=ListTail(l); } cnum=gcf_list(nl); if(IntegerValue(ListFirst(nl))<0) cnum*=-1; if(cnum==1) { RemoveList(nl); return; } l1=m2l; l=nl; while(!is_empty_list(l)) { SetCompoundArg(ListFirst(l1),1, NewInteger(IntegerValue(ListFirst(l))/cnum)); l=ListTail(l); l1=ListTail(l1); } RemoveList(nl); n=IntegerValue(CompoundArg1(CompoundArg2(a2))); d=IntegerValue(CompoundArg2(CompoundArg2(a2))); n*=cnum; cnum=gcf(n,d); n/=cnum; d/=cnum; SetCompoundArg(CompoundArg2(a2),1,NewInteger(n)); SetCompoundArg(CompoundArg2(a2),2,NewInteger(d)); return ; }
static int only_prm(Term a1) { List l1,l2; for(l1=CompoundArg1(a1);l1;l1=ListTail(l1)) { if(IntegerValue(CompoundArg2(ListFirst(l1)))<0) return 0; for(l2=CompoundArgN(ListFirst(l1),3);l2;l2=ListTail(l2)) { if(CompoundName(ListFirst(l2))==OPR_PARAMETER) continue; if(CompoundName(ListFirst(l2))==OPR_WILD) { List l3; for(l3=CompoundArg2(ListFirst(l2));l3;l3=ListTail(l3)) if(!only_prm(ListFirst(l3))) return 0; continue; } return 0; } } return 1; }
TypeId Consumer::GetTypeId(void) { static TypeId tid = TypeId("ns3::ndn::Consumer") .SetGroupName("Ndn") .SetParent<App>() .AddAttribute("StartSeq", "Initial sequence number", IntegerValue(0), MakeIntegerAccessor(&Consumer::m_seq), MakeIntegerChecker<int32_t>()) .AddAttribute("Prefix", "Name of the Interest", StringValue("/"), MakeNameAccessor(&Consumer::m_interestName), MakeNameChecker()) .AddAttribute("LifeTime", "LifeTime for interest packet", StringValue("2s"), MakeTimeAccessor(&Consumer::m_interestLifeTime), MakeTimeChecker()) .AddAttribute("RetxTimer", "Timeout defining how frequent retransmission timeouts should be checked", StringValue("50ms"), MakeTimeAccessor(&Consumer::GetRetxTimer, &Consumer::SetRetxTimer), MakeTimeChecker()) .AddTraceSource("LastRetransmittedInterestDataDelay", "Delay between last retransmitted Interest and received Data", MakeTraceSourceAccessor(&Consumer::m_lastRetransmittedInterestDataDelay), "ns3::ndn::Consumer::LastRetransmittedInterestDataDelayCallback") .AddTraceSource("FirstInterestDataDelay", "Delay between first transmitted Interest and received Data", MakeTraceSourceAccessor(&Consumer::m_firstInterestDataDelay), "ns3::ndn::Consumer::FirstInterestDataDelayCallback"); return tid; }
TypeId AccountingConsumer::GetTypeId(void) { static TypeId tid = TypeId("ns3::ndn::AccountingConsumer") .SetGroupName("Ndn") .SetParent<ConsumerCbr>() .AddConstructor<AccountingConsumer>() .AddAttribute("ConsumerID", "Consumer ID", IntegerValue(std::numeric_limits<uint32_t>::max()), MakeIntegerAccessor(&AccountingConsumer::m_id), MakeIntegerChecker<uint32_t>()) .AddAttribute("NumberOfContents", "Number of the Contents in total", StringValue("100"), MakeUintegerAccessor(&AccountingConsumer::SetNumberOfContents, &AccountingConsumer::GetNumberOfContents), MakeUintegerChecker<uint32_t>()) .AddAttribute("q", "parameter of improve rank", StringValue("0.7"), MakeDoubleAccessor(&AccountingConsumer::SetQ, &AccountingConsumer::GetQ), MakeDoubleChecker<double>()) .AddAttribute("s", "parameter of power", StringValue("0.7"), MakeDoubleAccessor(&AccountingConsumer::SetS, &AccountingConsumer::GetS), MakeDoubleChecker<double>()) .AddTraceSource("ReceivedMeaningfulContent", "Trace called every time meaningful content is received", MakeTraceSourceAccessor(&AccountingConsumer::m_receivedMeaningfulContent)); return tid; }
void DtPushConst( void ) { //===================== // Push constant. DXPush( IntegerValue( GetPtr() ) ); }
bool BooleanValue::convert(Value& Val) const { if (Val.getType() == Value::DOUBLE) { Val = DoubleValue(m_Value); return true; } else if (Val.getType() == Value::INTEGER) { Val = IntegerValue(m_Value); return true; } else if (Val.getType() == Value::VECTOR) { Val = VectorValue(1,m_Value); return true; } else if (Val.getType() == Value::MATRIX) { Val = MatrixValue(1,1,m_Value); return true; } return false; }
void alg2_decommon_s(Term a2) { Term cfl; List l; cfl=ConsumeCompoundArg(a2,3); if(is_empty_list(cfl)) return; for(l=CompoundArgN(a2,5);l;l=ListTail(l)) { List pfl; List l1,l2; pfl=ConsumeCompoundArg(ListFirst(l),2); for(l1=cfl;l1;l1=ListTail(l1)) { Atom p; p=CompoundArg1(ListFirst(l1)); for(l2=pfl;l2;l2=ListTail(l2)) { if(CompoundArg1(ListFirst(l2))==p) { int pw; pw=IntegerValue(CompoundArg2(ListFirst(l2))) +IntegerValue(CompoundArg2(ListFirst(l1))); SetCompoundArg(ListFirst(l2),2,NewInteger(pw)); break; } } if(is_empty_list(l2)) pfl=AppendFirst(pfl,CopyTerm(ListFirst(l1))); } rr: for(l1=pfl;l1;l1=ListTail(l1)) if(CompoundArg2(ListFirst(l1))==NewInteger(0)) { pfl=CutFromList(pfl,l1); goto rr; } pfl=SortedList(pfl,prtcmp); SetCompoundArg(ListFirst(l),2,pfl); } FreeAtomic(cfl); }
/* static int mlt_list1(List l) { int ret=1; while(!is_empty_list(l)) { if( is_empty_list(ListTail(l)) || !ListMember(ListTail(l),ListFirst(l))) ret*=IntegerValue(ListFirst(l)); l=ListTail(l); } return ret; } */ static int gcf_list(List l) { int ret; if(is_empty_list(l)) return 1; ret=IntegerValue(ListFirst(l)); if(ret<0) ret=-ret; l=ListTail(l); while(!is_empty_list(l)) { if(ret==1) return 1; ret=gcf(ret,IntegerValue(ListFirst(l))); l=ListTail(l); } return ret; }
static int mlt_list1(List l) { int ret=1; for(;l;l=ListTail(l)) { int i=IntegerValue(ListFirst(l)); i/=gcf(i,ret); ret*=i; } return ret; }
static void mult_no(List e1, int no) { while(!is_empty_list(e1)) { int v; v=IntegerValue(CompoundArg1(ListFirst(e1))); v*=no; SetCompoundArg(ListFirst(e1),1,NewInteger(v)); e1=ListTail(e1); } }
int main(int argc, char* argv[]) { // setting default parameters for PointToPoint links and channels Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps")); Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms")); Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20")); // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize CommandLine cmd; cmd.Parse(argc, argv); // Creating nodes NodeContainer nodes; nodes.Create(3); // Connecting nodes using two links PointToPointHelper p2p; p2p.Install(nodes.Get(0), nodes.Get(1)); p2p.Install(nodes.Get(1), nodes.Get(2)); // Install NDN stack on all nodes ndn::StackHelper ndnHelper; ndnHelper.SetDefaultRoutes(true); ndnHelper.InstallAll(); // Choosing forwarding strategy ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/multicast"); // Installing applications // Consumer ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); // Consumer will request /prefix/0, /prefix/1, ... consumerHelper.SetPrefix("/prefix"); consumerHelper.SetAttribute("Frequency", StringValue("1")); // 10 interests a second consumerHelper.SetAttribute("MaxSeq",IntegerValue(5)); consumerHelper.Install(nodes.Get(0)); // first node // Producer ndn::AppHelper producerHelper("ns3::ndn::Producer"); // Producer will reply to all requests starting with /prefix producerHelper.SetPrefix("/prefix"); producerHelper.SetAttribute("PayloadSize", StringValue("1024")); producerHelper.Install(nodes.Get(2)); // last node Simulator::Stop(Seconds(20.0)); Simulator::Run(); Simulator::Destroy(); return 0; }
TypeId icnVideoChunkingServer::GetTypeId() { static TypeId tid = TypeId("icnVideoChunkingServer") .SetParent<ndn::App>() .AddConstructor<icnVideoChunkingServer>() .AddAttribute("ServerId","ServerId", IntegerValue(0), MakeIntegerAccessor(&icnVideoChunkingServer::server_id), MakeIntegerChecker<uint32_t>()); return tid; }
static void invert_term(Term t) { { int i1,i2; i1=IntegerValue(CompoundArg1(t)); i2=IntegerValue(CompoundArg2(t)); if(i1<0 && i2>0) { i1=-i1; i2=-i2; goto ee; } if(i1>0 && i2<0) { i1=-i1; goto ee; } if(i1<0 && i2<0) { i2=-i2; goto ee; } ee: SetCompoundArg(t,1,NewInteger(i2)); SetCompoundArg(t,2,NewInteger(i1)); } { Term t1,t2; t1=ConsumeCompoundArg(t,3); t2=ConsumeCompoundArg(t,4); SetCompoundArg(t,3,t2); SetCompoundArg(t,4,t1); } }
static Term multiply(Term t1, Term t2) { Term ret; int n1,n2,d1,d2,num,den,cf; List l1,l2; ret=MakeCompound(A_MTERM,4); n1=IntegerValue(CompoundArg1(t1)); n2=IntegerValue(CompoundArg1(t2)); d1=IntegerValue(CompoundArg2(t1)); d2=IntegerValue(CompoundArg2(t2)); num=n1*n2; den=d1*d2; if(den<0) den=-den; cf=gcf(num,den); num/=cf; den/=cf; if(d1<0 && d2<0) { num=-num; } else if((d1<0 && d2>0) || (d1>0 && d2<0)) { den=-den; } SetCompoundArg(ret,1,NewInteger(num)); SetCompoundArg(ret,2,NewInteger(den)); l1=ConsumeCompoundArg(t1,3); l2=ConsumeCompoundArg(t2,3); SetCompoundArg(ret,3,ConcatList(l1,l2)); l1=ConsumeCompoundArg(t1,4); l2=ConsumeCompoundArg(t2,4); SetCompoundArg(ret,4,ConcatList(l1,l2)); FreeAtomic(t1); FreeAtomic(t2); return ret; }
static void GetDataConst( void ) { //============================== // Get a constant for data initialization. obj_ptr curr_fc; sym_id rep; if( ( DtFlags & DT_NO_MORE_CONSTS ) == 0 ) { if( DtRepCount == 0 ) { curr_fc = FCodeSeek( DtConstList ); rep = GetPtr(); if( rep != NULL ) { DtRepCount = IntegerValue( rep ); DtConstType = GetU16(); DtConst = GetPtr(); } else { DtFlags |= DT_NO_MORE_CONSTS; } DtConstList = FCodeSeek( curr_fc ); } DtRepCount--; } }
Term ProcCoefVrt(Term t, List ind) { List l,pl,ml; int ii; Term a2; int g=0, g5=0, re=0, im=0, abbr=0, cmplx=0; if(!is_compound(t) || CompoundArity(t)>2 || !is_list(CompoundArg1(t))) { ErrorInfo(0); puts("wrong parameters of CoefVrt function."); return 0; } if(lagr_hash==NULL) { ErrorInfo(107); puts("CoefVrt: no vertices"); return 0; } mmm=0; if(CompoundArity(t)==2) { List ol=CompoundArg2(t); if(!is_list(ol)) { ErrorInfo(107); puts("CoefVrt: second argument is not a list."); return 0; } for(;ol;ol=ListTail(ol)) { Term o=ListFirst(ol); if(is_compound(o)) { o=CompoundArg1(o); if(!is_atom(o) || !is_particle(o,0)) { ErrorInfo(0); printf("CoefVrt: ");WriteTerm(o); puts(" is not a particle.\n"); return 0; } mmm=o; continue; } if(!is_atom(o)) { ErrorInfo(0); printf("CoefVrt: ");WriteTerm(o); puts(" is not an option.\n"); return 0; } if(strcmp("gamma",AtomValue(o))==0) { g++; continue; } if(strcmp("gamma5",AtomValue(o))==0) { g5++; continue; } if(strcmp("re",AtomValue(o))==0) { re++; continue; } if(strcmp("im",AtomValue(o))==0) { im++; continue; } if(strcmp("abbr",AtomValue(o))==0) { abbr++; continue; } { ErrorInfo(0); printf("CoefVrt: ");WriteTerm(o); puts(" is not an option.\n"); return 0; } } } if(re&&im) re=im=0; pl=ConsumeCompoundArg(t,1); for(l=pl;l;l=ListTail(l)) if(is_function(ListFirst(l),0)) ChangeList(l,CallFunction(ListFirst(l),0)); /* for(l=pl;l;l=ListTail(l)) { Term aa=ListFirst(l); if(is_compound(aa)&&CompoundName(aa)==A_ANTI) ChangeList(l,GetAtomProperty(CompoundArg1(aa),A_ANTI)); }*/ pl=SortedList(pl,acmp); l=finda2(pl,0); if(mmm && !mmmpos) { ErrorInfo(0); printf("CoefVrt: particle "); WriteTerm(mmm); puts(" not found in the vertex"); return 0; } if(is_empty_list(l)) { ErrorInfo(108); printf("CoefVrt: vertex "); WriteTerm(pl); puts(" not found"); return NewInteger(0); } a2=CopyTerm(ListFirst(l)); alg2_symmetrize(a2); alg2_common_n(a2); { int sv=kill_gamma_pm; kill_gamma_pm=1; alg2_red_1pm5(a2); kill_gamma_pm=sv; } alg2_recommon_n(a2); ml=ConsumeCompoundArg(a2,5); for(l=ml;l;l=ListTail(l)) { List l1,ll; int tg=0, tg5=0, tm=0; for(l1=CompoundArgN(ListFirst(l),3);l1;l1=ListTail(l1)) { Term tt=ListFirst(l1); if(CompoundName(tt)==OPR_SPECIAL && CompoundArg1(tt)==A_GAMMA) tg++; if(CompoundName(tt)==OPR_SPECIAL && CompoundArg1(tt)==A_GAMMA5) tg5++; if(CompoundName(tt)==A_MOMENT && CompoundArg1(tt)== NewInteger(mmmpos)) tm++; } if(g!=tg || g5!=tg5 || (mmm && !tm)) { SetCompoundArg(ListFirst(l),1,0); continue; } if(!re && !im) continue; for(l1=CompoundArg2(ListFirst(l));l1;l1=ListTail(l1)) if(GetAtomProperty(CompoundArg1(ListFirst(l1)),A_ANTI)) cmplx++; } if( (re||im) && !cmplx) for(l=ml;l;l=ListTail(l)) { List ll,l1; if(CompoundArg1(ListFirst(l))==0) continue; ll=ConsumeCompoundArg(ListFirst(l),2); for(l1=ll;l1;l1=ListTail(l1)) if(CompoundArg1(ListFirst(l1))==A_I) break; if( (re && l1) || (im && !l1) ) SetCompoundArg(ListFirst(l),1,0); if(im && l1) ll=CutFromList(ll,l1); SetCompoundArg(ListFirst(l),2,ll); } rpt: for(l=ml;l;l=ListTail(l)) if(CompoundArg1(ListFirst(l))==0) { ml=CutFromList(ml,l); break; } if(l) goto rpt; SetCompoundArg(a2,5,ml); alg2_recommon_n(a2); alg2_common_s(a2); alg2_red_cos(a2); alg2_red_orth(a2); alg2_red_sico(a2); alg2_red_comsico(a2); alg2_recommon_n(a2); if(abbr) { int trisv=opTriHeu; alg2_eval_vrt(a2); doing_abbr=0; opTriHeu=trisv; } { int n,d; Term cf; Term res; n=IntegerValue(CompoundArg1(CompoundArg2(a2))); d=IntegerValue(CompoundArg2(CompoundArg2(a2))); cf=l2expr(CompoundArgN(a2,3),n); ml=CompoundArgN(a2,5); if(ml==0) return NewInteger(0); res=l2expr(CompoundArg2(ListFirst(ml)), IntegerValue(CompoundArg1(ListFirst(ml)))); for(l=ListTail(ml);l;l=ListTail(l)) { Term ccc; n=IntegerValue(CompoundArg1(ListFirst(l))); ccc=l2expr(CompoundArg2(ListFirst(l)),n>0?n:-n); if(n>0) res=MakeCompound2(OPR_PLUS,res,ccc); else res=MakeCompound2(OPR_MINUS,res,ccc); } if(res==NewInteger(1)) res=cf; else res=MakeCompound2(OPR_MLT,cf,res); if(d!=1) res=MakeCompound2(OPR_DIV,res,NewInteger(d)); if( (im||re) && cmplx) res=MakeCompound1(NewAtom(re?"creal":"cimag",0),res); return res; } return a2; }
void alg2_common_n(Term a2) { List m2l,l,l1,nl,dl; int cnum,cden,ti; m2l=CompoundArgN(a2,5); nl=dl=NewList(); l=m2l; if(is_empty_list(l)) return; while(!is_empty_list(l)) { Term t; t=ConsumeCompoundArg(ListFirst(l),1); nl=AppendLast(nl,CompoundArg1(t)); dl=AppendLast(dl,CompoundArg2(t)); FreeAtomic(t); l=ListTail(l); } cnum=gcf_list(nl); cden=gcf_list(dl); if(IntegerValue(ListFirst(nl))<0) cnum*=-1; l=nl; l1=dl; while(!is_empty_list(l)) { ChangeList(l,NewInteger(IntegerValue(ListFirst(l))/cnum)); ChangeList(l1,NewInteger(IntegerValue(ListFirst(l1))/cden)); l=ListTail(l); l1=ListTail(l1); } ti=mlt_list1(dl); l=nl; l1=dl; while(!is_empty_list(l)) { ChangeList(l, NewInteger(IntegerValue(ListFirst(l))*ti/IntegerValue(ListFirst(l1)))); l=ListTail(l); l1=ListTail(l1); } cden*=ti; ti=gcf_list(nl); cnum*=ti; l=nl; while(!is_empty_list(l)) { ChangeList(l,NewInteger(IntegerValue(ListFirst(l))/ti)); l=ListTail(l); } ti=gcf(cnum,cden); cnum/=ti; cden/=ti; RemoveList(dl); SetCompoundArg(a2,2,MakeCompound2(OPR_DIV,NewInteger(cnum),NewInteger(cden))); l=m2l; l1=nl; while(!is_empty_list(l)) { SetCompoundArg(ListFirst(l),1,ListFirst(l1)); l1=ListTail(l1); l=ListTail(l); } RemoveList(nl); return ; }
Term VarVer(Term t, Term ind) { List l,l1,l2; puts("Parameters"); l=all_param_list(); for(l1=l;!is_empty_list(l1);l1=ListTail(l1)) { Term aa; aa=CompoundArg1(ListFirst(l1)); if(!is_float(aa) && !is_integer(aa)) { printf("%s: ",AtomValue(CompoundName(ListFirst(l1)))); WriteTerm(aa); printf(" -> "); WriteTerm(dif_term(aa)); puts(""); } } puts("\nVertices"); l2=l=all_vert_list(); for(l1=l;!is_empty_list(l1);l1=ListTail(l1)) { Term a2; List l,lp,lm; a2=CopyTerm(ListFirst(l1)); alg2_symmetrize(a2); alg2_common_s(a2); alg2_common_n(a2); alg2_red_cos(a2); alg2_red_orth(a2); if(CompoundArg2(a2)==NewInteger(0) || is_empty_list(CompoundArgN(a2,5))) continue; WriteVertex(CompoundArg1(a2)); printf(" "); if(CompoundArgN(a2,3)) WriteTerm(CompoundArgN(a2,3)); else printf("[]"); printf(" "); lp=lm=NewList(); for(l=CompoundArgN(a2,3);!is_empty_list(l);l=ListTail(l)) { Term aa; aa=ListFirst(l); if(IntegerValue(CompoundArg2(aa))<0) { aa=CopyTerm(aa); SetCompoundArg(aa,2,NewInteger(-IntegerValue(CompoundArg2(aa)))); if(IntegerValue(CompoundArg2(aa))==1) lm=AppendLast(lm,CompoundArg1(aa)); else lm=AppendLast(lm,aa); } else { if(IntegerValue(CompoundArg2(aa))==1) lp=AppendLast(lp,CompoundArg1(aa)); else lp=AppendLast(lp,aa); } } if(lp) lp=l2mult(lp); if(lm) lm=l2mult(lm); if(lp==0 && lm==0) { printf("0"); goto cnt; } if(lm==0) { WriteTerm(dif_term(lp)); goto cnt; } if(lp==0) { WriteTerm(dif_term(MakeCompound2(OPR_DIV,NewInteger(1),lm))); goto cnt; } WriteTerm(dif_term(MakeCompound2(OPR_DIV,lp,lm))); cnt: puts(""); FreeAtomic(a2); } FreeAtomic(l2); return 0; }
/** * This scenario simulates a one-node two-custom-app scenario: * * +------+ <-----> (CustomApp) * | Node | * +------+ <-----> (Hijacker) * * NS_LOG=CustomApp ./waf --run=ndn-custom-apps */ int main(int argc, char* argv[]) { // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize CommandLine cmd; cmd.Parse(argc, argv); AnnotatedTopologyReader topologyReader("", 1); // topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-custom1.txt"); // topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-custom2.txt"); // topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-custom3.txt"); // topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-project.txt"); std::cout << "Reading topology file"; topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-project_400clients.txt"); topologyReader.Read(); std::cout << "Adding clients in vector"; vector<Ptr<Node>> clients; for(int i = 1; i <= 400; i++) { std::string cli = "client" + std::to_string(i); clients.push_back(Names::Find<Node>(cli)); } std::cout << "Adding Cache servers in vector"; vector<Ptr<Node>> cacheServers; for(int i = 1; i <= 7; i++) { std::string cs = "cache" + std::to_string(i); cacheServers.push_back(Names::Find<Node>(cs)); } // Creating nodes // Ptr<Node> node = CreateObject<Node>(); // Install Content Store stack on cache node ndn::StackHelper ndnHelperCache; // ndnHelperCache.SetOldContentStore("ns3::ndn::cs::Lru", "MaxSize", "2"); //ndnHelperCache.SetOldContentStore("ns3::ndn::cs::Nocache"); // ndnHelperCache.SetOldContentStore("ns3::ndn::cs::ProbCacheExt::Lru", "MaxSize", "2"); ndnHelperCache.setCsSize(2); for(int i = 0; i < (int)cacheServers.size(); i++) { ndnHelperCache.Install(cacheServers[i]); } // Install NDN stack on all nodes /* ndn::StackHelper ndnHelper; ndnHelper.SetDefaultRoutes(true); ndnHelper.InstallAll();*/ // Install NDN stack on rest of the nodes ndn::StackHelper ndnHelper; for(int i = 0; i < (int)clients.size(); i++) { ndnHelper.Install(clients[i]); } // ndnHelper.Install(Names::Find<Node>("client2")); // ndnHelper.Install(Names::Find<Node>("client3")); ndnHelper.Install(Names::Find<Node>("originServer")); // Choosing forwarding strategy ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/best-route"); // Ptr<Node> consumers1 = Names::Find<Node>("client1"); // Ptr<Node> consumers2 = Names::Find<Node>("client2"); // Ptr<Node> consumers3 = Names::Find<Node>("client3"); // Ptr<Node> consumers[3] = {Names::Find<Node>("client1"), Names::Find<Node>("client2"), Names::Find<Node>("client3")}; Ptr<Node> producer = Names::Find<Node>("originServer"); cout << "Installing Global routing interface on all nodes"; // Installing global routing interface on all nodes ndn::GlobalRoutingHelper ndnGlobalRoutingHelper; ndnGlobalRoutingHelper.InstallAll(); cout << " Creating app1...."; // App1 /*ndn::AppHelper app1("CustomApp"); app1.SetPrefix("/root"); app1.Install(consumers1); app1.Install(consumers2); app1.Install(consumers3);*/ // std::string content[] = {"alpha", "beta", "gamma", "delta", "epsilon"}; // const int nrolls=100000; // number of experiments // const int nstars=100; // maximum number of stars to distribute std::default_random_engine generator; std::lognormal_distribution<double> distribution(0.0,1.0); //int p[100]={}; /* for (int i=0; i<nrolls; ++i) { double number = distribution(generator); if ((number>=0.0)&&(number<10.0)) ++p[int(number)]; }*/ int j = 0; /* int alphaCount = 1; int betaCount = 2; int gammaCount = 3; int deltaCount = 4; int epsilonCount = 10; */ for (int k = 0; k < 1; k++) { for (int i = 0; i < 200; i++) { for(int l = 0; l < 2; l++) { j = int(distribution(generator)); // j = p[i]*nstars/nrolls; // std::cout << "i: " << i; ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); consumerHelper.SetAttribute("Frequency", StringValue("1")); consumerHelper.SetAttribute("Content", IntegerValue(j)); int temp = 0; if(l == 0) { temp = i; } else { temp = i + 200; } consumerHelper.SetPrefix("/root/" + Names::FindName(clients[temp])); ns3::ApplicationContainer ac = consumerHelper.Install(clients[temp]); ac.Start(Seconds (double(k * 1000 + ( (i * 10) + 1)))); ac.Stop(Seconds (double(k * 1000 + ( (i * 10) + 2)))); } /* if((j % 5) == 0) { if(alphaCount == 0) { alphaCount++; } else { alphaCount--; } j++; } else if ((j % 5) == 1) { if(betaCount >= 1) { betaCount--; } else { betaCount = 2; j++; } } else if ((j % 5) == 2) { if(gammaCount >= 1) { gammaCount--; } else { gammaCount = 3; j++; } } else if ((j % 5) == 3) { if(deltaCount >= 1) { deltaCount--; } else { deltaCount = 4; j++; } } else if ((j % 5) == 4) { if(epsilonCount >= 1) { epsilonCount--; } else { epsilonCount = 10; j++; } } */ } } /* ndn::AppHelper consumerHelper2("ns3::ndn::ConsumerCbr"); consumerHelper2.SetAttribute("Frequency", StringValue("1")); consumerHelper2.SetPrefix("/root/" + Names::FindName(consumers[1])); // consumerHelper.Install(consumers[i]); //consumerHelper2.Install(consumers[1]).Start(Seconds (2.0)); ns3::ApplicationContainer ac2 = consumerHelper2.Install(consumers[1]); ac2.Start(Seconds (2.0)); ac2.Stop(Seconds (3.0)); //consumerHelper2.Install(consumers[0]).Stop(Seconds (3.0)); ndn::AppHelper consumerHelper3("ns3::ndn::ConsumerCbr"); consumerHelper3.SetAttribute("Frequency", StringValue("1")); consumerHelper3.SetPrefix("/root/" + Names::FindName(consumers[2])); // consumerHelper.Install(consumers[i]); //consumerHelper3.Install(consumers[2]).Start(Seconds (3.0)); ns3::ApplicationContainer ac3 = consumerHelper3.Install(consumers[2]); ac3.Start(Seconds (3.0)); ac3.Stop(Seconds (4.0)); */ //consumerHelper3.Install(consumers[0]).Stop(Seconds (4.0)); // App2 //ndn::AppHelper app2("Hijacker"); //app2.Install(producer); // last node cout << " Creating Producer"; ndn::AppHelper producerHelper("ns3::ndn::Producer"); // Producer will reply to all requests starting with /prefix producerHelper.SetAttribute("PayloadSize", StringValue("1024")); producerHelper.SetAttribute("Freshness", TimeValue (Seconds (2.0))); ndnGlobalRoutingHelper.AddOrigins("/root", producer); producerHelper.SetPrefix("/root"); producerHelper.Install(producer); // Calculate and install FIBs ndn::GlobalRoutingHelper::CalculateRoutes(); Simulator::Stop(Seconds(2004.0)); // Simulator::Stop(Seconds(9993.0)); Simulator::Run(); Simulator::Destroy(); return 0; }
void alg1_opt_let(Term a1) { List l,l1,l2,lm=ConsumeCompoundArg(a1,1); List nl=0; Label mylbl=NewLabel(); /*printf("%d -> ",ListLength(lm));*/ for(l=lm;l;l=ListTail(l)) { Term m1=ListFirst(l); int n,d,g; List ln=ConsumeCompoundArg(m1,3); List ld=ConsumeCompoundArg(m1,4); Term f1=0, f2=0, w=0; n=IntegerValue(CompoundArg1(m1)); d=IntegerValue(CompoundArg2(m1)); rpt1: for(l1=ld;l1;l1=ListTail(l1)) { int n=ListMember(ln,ListFirst(l1)); if(n) { ld=CutFromList(ld,l1); l1=ListNthList(ln,n); ln=CutFromList(ln,l1); goto rpt1; } if(CompoundArg2(ListFirst(l1))==A_SQRT2) { Term t=ListFirst(l1); ChangeList(l1,0); ld=CutFromList(ld,l1); ln=AppendFirst(ln,t); d*=2; goto rpt1; } } rpt2: for(l1=ln;l1;l1=ListTail(l1)) if(CompoundArg2(ListFirst(l1))==A_SQRT2) { List l2; for(l2=ListTail(l1);l2;l2=ListTail(l2)) if(CompoundArg2(ListFirst(l2))==A_SQRT2) { ln=CutFromList(ln,l1); ln=CutFromList(ln,l2); n*=2; goto rpt2; } } g=gcf(n,d); n/=g; d/=g; for(l1=ln;l1;l1=l1?ListTail(l1):0) { Term sp=ListFirst(l1); if(CompoundName(sp)==OPR_PARAMETER) continue; if(CompoundName(sp)==OPR_FIELD) { if(f1==0) f1=l1; else if(f2==0) f2=l1; else { ErrorInfo(1280); puts("bad let-sub: >2 prtc"); return; } continue; } if(CompoundName(sp)==OPR_WILD) { if(w) { ErrorInfo(1281); puts("bad let-sub: unk spec"); return; } w=l1; continue; } ErrorInfo(110); WriteTerm(sp);puts(" : bad let: unk stuff"); return; } if(f2==0) { ErrorInfo(112); puts("bad let-subs: not 2 prtc"); return; } l1=f1;f1=ListFirst(f1);ChangeList(l1,0);ln=CutFromList(ln,l1); l1=f2;f2=ListFirst(f2);ChangeList(l1,0);ln=CutFromList(ln,l1); if(w) {l1=w;w=ListFirst(w);ChangeList(l1,0);ln=CutFromList(ln,l1);} ln=SortedList(ln,prmcmp); ld=SortedList(ld,prmcmp); if((GetAtomProperty(CompoundArg2(f1),A_ANTI)==CompoundArg2(f1) || GetAtomProperty(CompoundArg2(f2),A_ANTI)==CompoundArg2(f2)) && strcmp(AtomValue(CompoundArg2(f1)),AtomValue(CompoundArg2(f2)))>0) { Term tmp=f1; f1=f2; f2=tmp; } if(ListLength(CompoundArg1(f1))==1 && ListLength(CompoundArg1(f1))==1) { Term i1=ListFirst(CompoundArg1(f1)); Term i2=ListFirst(CompoundArg1(f2)); if(CompoundName(CompoundArg1(i1))!=A_COLOR || CompoundName(CompoundArg1(i2))!=A_COLOR || CompoundArg2(i1)!=CompoundArg2(i2)) { ErrorInfo(233); puts("bad color stru in let-sub."); return; } SetCompoundArg(i1,2,mylbl); SetCompoundArg(i2,2,mylbl); } ln=AppendLast(ln,f1); ln=AppendLast(ln,f2); if(w) ln=AppendLast(ln,w); SetCompoundArg(m1,1,NewInteger(n)); SetCompoundArg(m1,2,NewInteger(d)); SetCompoundArg(m1,3,ln); SetCompoundArg(m1,4,ld); for(l1=nl;l1;l1=ListTail(l1)) { if(EqualTerms(CompoundArgN(ListFirst(l1),3),ln) && EqualTerms(CompoundArgN(ListFirst(l1),4),ld) && IntegerValue(CompoundArg2(ListFirst(l1)))*d>0) { Term om1=ListFirst(l1); int n1=IntegerValue(CompoundArg1(om1)); int d1=IntegerValue(CompoundArg2(om1)); int rn,rd,cc=0; if(d1<0) { d=-d;d1=-d1;cc=1; } rn=n*d1+n1*d; rd=d*d1; if(rn==0) { nl=CutFromList(nl,l1); break; } g=gcf(rn,rd); rn/=g; rd/=g; if(cc) rd=-rd; SetCompoundArg(om1,1,NewInteger(rn)); SetCompoundArg(om1,2,NewInteger(rd)); FreeAtomic(m1); break; } } if(l1==0) nl=AppendLast(nl,m1); } RemoveList(lm); /*DumpList(nl);*/ /*printf("%d\n",ListLength(nl));*/ SetCompoundArg(a1,1,nl); }
static List mk_let_d(Term m1, Term a1) { List l,l2; List lb; List sd; int num1,den1; int io1=0,io2=0,rmn=0; for(l=CompoundArgN(m1,3);l;l=ListTail(l)) { Term prp=0; if(CompoundName(ListFirst(l))==OPR_PARAMETER) prp=GetAtomProperty(CompoundArg2(ListFirst(l)),A_INFINITESIMAL); if(prp && IntegerValue(CompoundArg1(prp))>0) io1+=IntegerValue(CompoundArg1(prp)); if(CompoundName(ListFirst(l))==A_INFINITESIMAL) io1+=IntegerValue(CompoundArg2(ListFirst(l))); } l=ConsumeCompoundArg(a1,1); FreeAtomic(a1); a1=l; for(l2=a1;l2;l2=ListTail(l2)) { Term m11=ListFirst(l2); io2=0; for(l=CompoundArgN(m11,3);l;l=ListTail(l)) { Term prp=0; if(CompoundName(ListFirst(l))==OPR_PARAMETER) prp=GetAtomProperty(CompoundArg2(ListFirst(l)),A_INFINITESIMAL); if(prp && IntegerValue(CompoundArg1(prp))>0) io2+=IntegerValue(CompoundArg1(prp)); if(CompoundName(ListFirst(l))==A_INFINITESIMAL) io2+=IntegerValue(CompoundArg2(ListFirst(l))); } if(io1+io2>infi_order) { FreeAtomic(ListFirst(l2)); ChangeList(l2,0); rmn++; } } if(rmn) do { for(l=a1;l;l=ListTail(l)) if(ListFirst(l)==0) { a1=CutFromList(a1,l); break; } } while(l); num1=IntegerValue(ConsumeCompoundArg(m1,1)); den1=IntegerValue(ConsumeCompoundArg(m1,2)); l=ConsumeCompoundArg(m1,3); sd=ConsumeCompoundArg(m1,4); lb=l; FreeAtomic(m1); l=a1; while(!is_empty_list(l)) { int n1,n2,d1,d2,num,den,cf; List lb1,lm; m1=ListFirst(l); lm=ConsumeCompoundArg(m1,3); lb1=CopyTerm(lb); lb1=ConcatList(lb1,lm); SetCompoundArg(m1,3,lb1); lm=ConsumeCompoundArg(m1,4); lm=ConcatList(lm,CopyTerm(sd)); SetCompoundArg(m1,4,lm); n1=num1; d1=den1; n2=IntegerValue(CompoundArg1(m1)); d2=IntegerValue(CompoundArg2(m1)); num=n1*n2; den=d1*d2; if(den<0) den=-den; cf=gcf(num,den); num/=cf; den/=cf; if(d1<0 && d2<0) { num=-num; } else if((d1<0 && d2>0) || (d1>0 && d2<0)) { den=-den; } SetCompoundArg(m1,1,NewInteger(num)); SetCompoundArg(m1,2,NewInteger(den)); l=ListTail(l); } FreeAtomic(lb); FreeAtomic(sd); return a1; }
static List alg1_s_w_m_1(Term m1, Term by) { Atomic ind; int range; int i1,i2; int c1,c2; List l1; List ret,rete; int i; i1=i2=0; c1=c2=0; i=1; ind=CompoundArg1(by); range=IntegerValue(CompoundArg2(by)); l1=CompoundArgN(m1,3); while(!is_empty_list(l1)) { Term t1; t1=ListFirst(l1); if(CompoundName(t1)==OPR_WILD) { List l2; int no; no=1; l2=CompoundArg1(t1); while(!is_empty_list(l2)) { Term t2; t2=ListFirst(l2); if(CompoundArg2(t2)==ind) { if(c1==0) { c1=i; i1=no; } else if(is_empty_list(c2)) { c2=i; i2=no; } else { printf("Internal error (3rd index)\n"); longjmp(alg1_jmp_buf,1); } } no++; l2=ListTail(l2); } } i++; l1=ListTail(l1); } /* printf("First: %lx %d\n",c1,i1); printf("Second: %lx %d\n",c2,i2); */ ret=NewList(); rete=ret; for(i=1;i<=range;i++) { List nn=alg1_sub_w(m1,ind,c1,i1,c2,i2,i); if(nn) { if(ret==0) {ret=nn;rete=ret;} else ListConcat(rete,nn); while(ListTail(rete)) rete=ListTail(rete); } /*ret=ConcatList(ret,nn);*/ } return ret; }
int run(int argc, char* argv[]) { delayFile.open(DELAY_OUTPUT_FILE_NAME); // setting default parameters for PointToPoint links and channels Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1000Mbps")); Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms")); Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("4294967295")); // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize CommandLine cmd; cmd.Parse(argc, argv); // Creating nodes NodeContainer nodes; nodes.Create(NUM_OF_CONSUMERS + NUM_OF_ROUTERS + NUM_OF_PRODUCER); // Connecting nodes using two links // Connecting nodes using two links PointToPointHelper p2p; // Connecting consumers to edge routers int g = 0; for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (0 + NUM_OF_CONSUMERS)); // C0 <--> R0 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (1 + NUM_OF_CONSUMERS)); // C1 <--> R1 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (3 + NUM_OF_CONSUMERS)); // C2 <--> R3 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (5 + NUM_OF_CONSUMERS)); // C3 <--> R5 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (6 + NUM_OF_CONSUMERS)); // C4 <--> R6 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (10 + NUM_OF_CONSUMERS)); // C5 <--> R10 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (8 + NUM_OF_CONSUMERS)); // C6 <--> R8 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (11 + NUM_OF_CONSUMERS)); // C7 <--> R11 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (12 + NUM_OF_CONSUMERS)); // C8 <--> R12 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (18 + NUM_OF_CONSUMERS)); // C9 <--> R18 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (17 + NUM_OF_CONSUMERS)); // C10 <--> R17 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (20 + NUM_OF_CONSUMERS)); // C11 <--> R20 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (24 + NUM_OF_CONSUMERS)); // C12 <--> R24 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (29 + NUM_OF_CONSUMERS)); // C13 <--> R2 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (28 + NUM_OF_CONSUMERS)); // C14 <--> R28 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (21 + NUM_OF_CONSUMERS)); // C15 <--> R21 // Connect routers p2p.Install (nodes.Get (0 + NUM_OF_CONSUMERS), nodes.Get (9 + NUM_OF_CONSUMERS)); // R0 <--> R9 p2p.Install (nodes.Get (1 + NUM_OF_CONSUMERS), nodes.Get (15 + NUM_OF_CONSUMERS)); // R1 <--> R15 p2p.Install (nodes.Get (2 + NUM_OF_CONSUMERS), nodes.Get (9 + NUM_OF_CONSUMERS)); // R2 <--> R9 p2p.Install (nodes.Get (3 + NUM_OF_CONSUMERS), nodes.Get (4 + NUM_OF_CONSUMERS)); // R3 <--> R4 p2p.Install (nodes.Get (4 + NUM_OF_CONSUMERS), nodes.Get (7 + NUM_OF_CONSUMERS)); // R4 <--> R7 p2p.Install (nodes.Get (4 + NUM_OF_CONSUMERS), nodes.Get (14 + NUM_OF_CONSUMERS)); // R4 <--> R14 p2p.Install (nodes.Get (4 + NUM_OF_CONSUMERS), nodes.Get (9 + NUM_OF_CONSUMERS)); // R4 <--> R9 p2p.Install (nodes.Get (4 + NUM_OF_CONSUMERS), nodes.Get (16 + NUM_OF_CONSUMERS)); // R4 <--> R16 p2p.Install (nodes.Get (4 + NUM_OF_CONSUMERS), nodes.Get (25 + NUM_OF_CONSUMERS)); // R4 <--> R25 p2p.Install (nodes.Get (5 + NUM_OF_CONSUMERS), nodes.Get (13 + NUM_OF_CONSUMERS)); // R5 <--> R13 p2p.Install (nodes.Get (6 + NUM_OF_CONSUMERS), nodes.Get (7 + NUM_OF_CONSUMERS)); // R6 <--> R7 p2p.Install (nodes.Get (7 + NUM_OF_CONSUMERS), nodes.Get (9 + NUM_OF_CONSUMERS)); // R7 <--> R9 p2p.Install (nodes.Get (7 + NUM_OF_CONSUMERS), nodes.Get (14 + NUM_OF_CONSUMERS)); // R7 <--> R14 p2p.Install (nodes.Get (7 + NUM_OF_CONSUMERS), nodes.Get (22 + NUM_OF_CONSUMERS)); // R7 <--> R22 p2p.Install (nodes.Get (7 + NUM_OF_CONSUMERS), nodes.Get (23 + NUM_OF_CONSUMERS)); // R7 <--> R23 p2p.Install (nodes.Get (8 + NUM_OF_CONSUMERS), nodes.Get (9 + NUM_OF_CONSUMERS)); // R8 <--> R9 p2p.Install (nodes.Get (9 + NUM_OF_CONSUMERS), nodes.Get (13 + NUM_OF_CONSUMERS)); // R9 <--> R13 p2p.Install (nodes.Get (9 + NUM_OF_CONSUMERS), nodes.Get (14 + NUM_OF_CONSUMERS)); // R9 <--> R14 p2p.Install (nodes.Get (9 + NUM_OF_CONSUMERS), nodes.Get (22 + NUM_OF_CONSUMERS)); // R9 <--> R22 p2p.Install (nodes.Get (9 + NUM_OF_CONSUMERS), nodes.Get (25 + NUM_OF_CONSUMERS)); // R9 <--> R25 p2p.Install (nodes.Get (9 + NUM_OF_CONSUMERS), nodes.Get (27 + NUM_OF_CONSUMERS)); // R9 <--> R27 p2p.Install (nodes.Get (10 + NUM_OF_CONSUMERS), nodes.Get (14 + NUM_OF_CONSUMERS)); // R10 <--> R14 p2p.Install (nodes.Get (11 + NUM_OF_CONSUMERS), nodes.Get (13 + NUM_OF_CONSUMERS)); // R11 <--> R13 p2p.Install (nodes.Get (12 + NUM_OF_CONSUMERS), nodes.Get (13 + NUM_OF_CONSUMERS)); // R12 <--> R13 p2p.Install (nodes.Get (13 + NUM_OF_CONSUMERS), nodes.Get (14 + NUM_OF_CONSUMERS)); // R13 <--> R14 p2p.Install (nodes.Get (13 + NUM_OF_CONSUMERS), nodes.Get (22 + NUM_OF_CONSUMERS)); // R13 <--> R22 p2p.Install (nodes.Get (13 + NUM_OF_CONSUMERS), nodes.Get (25 + NUM_OF_CONSUMERS)); // R13 <--> R25 p2p.Install (nodes.Get (13 + NUM_OF_CONSUMERS), nodes.Get (27 + NUM_OF_CONSUMERS)); // R13 <--> R27 p2p.Install (nodes.Get (14 + NUM_OF_CONSUMERS), nodes.Get (15 + NUM_OF_CONSUMERS)); // R14 <--> R15 p2p.Install (nodes.Get (14 + NUM_OF_CONSUMERS), nodes.Get (18 + NUM_OF_CONSUMERS)); // R14 <--> R18 p2p.Install (nodes.Get (14 + NUM_OF_CONSUMERS), nodes.Get (19 + NUM_OF_CONSUMERS)); // R14 <--> R19 p2p.Install (nodes.Get (15 + NUM_OF_CONSUMERS), nodes.Get (16 + NUM_OF_CONSUMERS)); // R15 <--> R16 p2p.Install (nodes.Get (15 + NUM_OF_CONSUMERS), nodes.Get (19 + NUM_OF_CONSUMERS)); // R15 <--> R19 p2p.Install (nodes.Get (15 + NUM_OF_CONSUMERS), nodes.Get (21 + NUM_OF_CONSUMERS)); // R15 <--> R21 p2p.Install (nodes.Get (15 + NUM_OF_CONSUMERS), nodes.Get (22 + NUM_OF_CONSUMERS)); // R15 <--> R22 p2p.Install (nodes.Get (15 + NUM_OF_CONSUMERS), nodes.Get (23 + NUM_OF_CONSUMERS)); // R15 <--> R23 p2p.Install (nodes.Get (15 + NUM_OF_CONSUMERS), nodes.Get (25 + NUM_OF_CONSUMERS)); // R15 <--> R25 p2p.Install (nodes.Get (15 + NUM_OF_CONSUMERS), nodes.Get (27 + NUM_OF_CONSUMERS)); // R15 <--> R27 p2p.Install (nodes.Get (16 + NUM_OF_CONSUMERS), nodes.Get (23 + NUM_OF_CONSUMERS)); // R16 <--> R23 p2p.Install (nodes.Get (16 + NUM_OF_CONSUMERS), nodes.Get (27 + NUM_OF_CONSUMERS)); // R16 <--> R27 p2p.Install (nodes.Get (17 + NUM_OF_CONSUMERS), nodes.Get (23 + NUM_OF_CONSUMERS)); // R17 <--> R23 // 18 done p2p.Install (nodes.Get (19 + NUM_OF_CONSUMERS), nodes.Get (22 + NUM_OF_CONSUMERS)); // R19 <--> R22 p2p.Install (nodes.Get (20 + NUM_OF_CONSUMERS), nodes.Get (25 + NUM_OF_CONSUMERS)); // R20 <--> R25 p2p.Install (nodes.Get (21 + NUM_OF_CONSUMERS), nodes.Get (22 + NUM_OF_CONSUMERS)); // R21 <--> R22 p2p.Install (nodes.Get (21 + NUM_OF_CONSUMERS), nodes.Get (27 + NUM_OF_CONSUMERS)); // R21 <--> R27 p2p.Install (nodes.Get (22 + NUM_OF_CONSUMERS), nodes.Get (23 + NUM_OF_CONSUMERS)); // R22 <--> R23 p2p.Install (nodes.Get (22 + NUM_OF_CONSUMERS), nodes.Get (28 + NUM_OF_CONSUMERS)); // R22 <--> R28 p2p.Install (nodes.Get (22 + NUM_OF_CONSUMERS), nodes.Get (29 + NUM_OF_CONSUMERS)); // R22 <--> R29 p2p.Install (nodes.Get (23 + NUM_OF_CONSUMERS), nodes.Get (24 + NUM_OF_CONSUMERS)); // R23 <--> R24 p2p.Install (nodes.Get (23 + NUM_OF_CONSUMERS), nodes.Get (25 + NUM_OF_CONSUMERS)); // R23 <--> R25 p2p.Install (nodes.Get (23 + NUM_OF_CONSUMERS), nodes.Get (27 + NUM_OF_CONSUMERS)); // R23 <--> R27 // 24 done // 25 done p2p.Install (nodes.Get (26 + NUM_OF_CONSUMERS), nodes.Get (27 + NUM_OF_CONSUMERS)); // R26 <--> R27 // 27 done // 28 done // 29 done // Connecting producer(s) int producerId = 0 + NUM_OF_CONSUMERS + NUM_OF_ROUTERS; p2p.Install (nodes.Get (producerId), nodes.Get (0 + NUM_OF_CONSUMERS)); // P0 <--> R0 // Install NDN stack without cache ndn::StackHelper ndnHelperNoCache; // ndnHelperNoCache.SetDefaultRoutes(true); ndnHelperNoCache.SetOldContentStore("ns3::ndn::cs::Nocache"); // no cache // Install on consumers for (int i = 0; i < NUM_OF_CONSUMERS; i++) { ndnHelperNoCache.Install(nodes.Get(i)); } // Install on producer(s) ndnHelperNoCache.Install(nodes.Get(0 + NUM_OF_CONSUMERS + NUM_OF_ROUTERS)); // Install NDN stack with cache ndn::StackHelper ndnHelperWithCache; // ndnHelperWithCache.SetDefaultRoutes(true); ndnHelperWithCache.SetOldContentStore("ns3::ndn::cs::Freshness::Lru", "MaxSize", "0"); // Install on routers for (int i = NUM_OF_CONSUMERS; i < NUM_OF_CONSUMERS + NUM_OF_ROUTERS; i++) { ndnHelperWithCache.InstallWithCallback(nodes.Get(i), (size_t)&ForwardingDelay, i, USE_PINT); } // Consumers ndn::AppHelper consumerHelperHonest("ns3::ndn::AccountingEncrConsumer"); // Consumer will request /prefix/A/0, /prefix/A/1, ... consumerHelperHonest.SetAttribute("Frequency", StringValue("1")); // 10 interests a second consumerHelperHonest.SetAttribute("Randomize", StringValue("uniform")); consumerHelperHonest.SetAttribute("StartSeq", IntegerValue(0)); for(int i=0; i < NUM_OF_CONSUMERS; i++) { consumerHelperHonest.SetPrefix("/prefix/A/" + std::to_string(i)); ApplicationContainer consumer = consumerHelperHonest.Install(nodes.Get(i)); consumer.Start(Seconds(0)); std::ostringstream node_id; node_id << i; Config::ConnectWithoutContext("/NodeList/" + node_id.str() + "/ApplicationList/0/ReceivedMeaningfulContent", MakeCallback(ReceivedMeaningfulContent)); } // Producer ndn::AppHelper producerHelper("ns3::ndn::AccountingEncrProducer"); // Producer will reply to all requests starting with /prefix/A. For /prefix/B we expect NACK producerHelper.SetPrefix("/prefix/A"); producerHelper.SetAttribute("PayloadSize", StringValue("1024")); producerHelper.Install(nodes.Get(producerId)); ndn::GlobalRoutingHelper ndnGlobalRoutingHelper; ndnGlobalRoutingHelper.Install(nodes); std::string prefix = "/prefix/A"; ndnGlobalRoutingHelper.AddOrigins(prefix, nodes.Get(producerId)); ndn::GlobalRoutingHelper::CalculateRoutes(); // Traces ndn::L3RateTracer::InstallAll(RATE_OUTPUT_FILE_NAME, Seconds(1.0)); Simulator::Stop(Seconds(SIMULATION_DURATION)); Simulator::Run(); Simulator::Destroy(); delayFile.close(); return 0; }
Term ExpandTerm(Term t) { List il=0; Term res; /*puts(""); WriteTerm(t); puts("\n");*/ if(is_compound(t) && (CompoundName(t)==OPR_USCORE || CompoundName(t)==OPR_CARET)) { t=SplitIndices(t,&il); if(t==0) longjmp(alg1_jmp_buf,1); } if(is_function(t,NULL)) return ExpandTerm(CallFunction(t,il)); if(is_float(t)) { ErrorInfo(303); printf(" illegal use of floating point number %f.\n",FloatValue(t)); FreeAtomic(t); longjmp(alg1_jmp_buf,1); } if(is_integer(t)) { if(IntegerValue(t)==0) return 0; if(il) { ErrorInfo(304); puts("Integer can't have indices.\n"); longjmp(alg1_jmp_buf,1); } res=MakeCompound(A_MTERM,4); SetCompoundArg(res,1,t); SetCompoundArg(res,2,NewInteger(1)); return AppendFirst(0,res); } if(t==A_I) { res=MakeCompound(A_MTERM,4); SetCompoundArg(res,1,NewInteger(1)); SetCompoundArg(res,2,NewInteger(-1)); return AppendFirst(0,res); } if(is_atom(t) || (is_compound(t) && CompoundName(t)==A_FBRACET) || (is_compound(t) && CompoundName(t)==A_ALG1 && CompoundArity(t)==2) || (is_compound(t) && (CompoundName(t)==A_SIN || CompoundName(t)==A_COS) && CompoundArity(t)<3 && is_integer(CompoundArg1(t)))) return AtomicTo1(t,il); if(!is_empty_list(il)) { ErrorInfo(307); printf(" bad indices "); WriteTerm(il); printf(" in expression.\n"); longjmp(alg1_jmp_buf,1); } if(opSetGpm && is_compound(t) && CompoundArity(t)==2 && CompoundArg1(t)==NewInteger(1) && is_atom(CompoundArg2(t)) && (CompoundArg2(t)==A_GAMMA5 || GetAtomProperty(CompoundArg2(t),A_GAMMA5)) && (CompoundName(t)==OPR_PLUS || CompoundName(t)==OPR_MINUS)) { Term ret,sp; ret=MakeCompound(A_MTERM,4); SetCompoundArg(ret,1,NewInteger(2)); SetCompoundArg(ret,2,NewInteger(1)); sp=MakeCompound(OPR_SPECIAL,2); if(CompoundName(t)==OPR_PLUS) SetCompoundArg(sp,2,A_GAMMAP); else SetCompoundArg(sp,2,A_GAMMAM); SetCompoundArg(sp,1,CopyTerm(GetAtomProperty(A_GAMMA5,PROP_INDEX))); SetCompoundArg(ret,3,AppendLast(NewList(),sp)); return AppendLast(NewList(),ret); } if(is_compound(t) && CompoundName(t)==OPR_PLUS && CompoundArity(t)==2) { Term t1,t2; t1=ConsumeCompoundArg(t,1); t2=ConsumeCompoundArg(t,2); FreeAtomic(t); t1=ExpandTerm(t1); t2=ExpandTerm(t2); return ConcatList(t1,t2); } if(is_compound(t) && CompoundName(t)==OPR_MINUS && CompoundArity(t)==2) { Term t1,t2; t1=ConsumeCompoundArg(t,1); t2=ConsumeCompoundArg(t,2); FreeAtomic(t); t1=ExpandTerm(t1); t2=ExpandTerm(t2); mult_no(t2,-1); return ConcatList(t1,t2); } if(is_compound(t) && CompoundName(t)==OPR_MINUS && CompoundArity(t)==1) { Term t1; t1=ConsumeCompoundArg(t,1); FreeAtomic(t); t1=ExpandTerm(t1); mult_no(t1,-1); return t1; } if(is_compound(t) && CompoundName(t)==OPR_MLT && CompoundArity(t)==2) { Term t1,t2; t1=ConsumeCompoundArg(t,1); t2=ConsumeCompoundArg(t,2); FreeAtomic(t); t1=ExpandTerm(t1); t2=ExpandTerm(t2); return multiply_l(t1,t2); } if(is_compound(t) && CompoundName(t)==OPR_DIV && CompoundArity(t)==2) { Term t1,t2,t2s; t1=ConsumeCompoundArg(t,1); t2=ConsumeCompoundArg(t,2); FreeAtomic(t); t1=ExpandTerm(t1); t2s=CopyTerm(t2); t2=ExpandTerm(t2); if(ListLength(t2)!=1) { ErrorInfo(306); printf(" cannot divide by \'"); WriteTerm(t2s); printf("\'.\n"); FreeAtomic(t1); FreeAtomic(t2); FreeAtomic(t2s); longjmp(alg1_jmp_buf,1); } FreeAtomic(t2s); invert_term(ListFirst(t2)); return multiply_l(t1,t2); } if(is_compound(t) && CompoundName(t)==OPR_POW && CompoundArity(t)==2) { Term t1,t2,ret; int i,pp; t1=ConsumeCompoundArg(t,1); t2=ConsumeCompoundArg(t,2); FreeAtomic(t); if(!is_integer(t2) || IntegerValue(t2)<1) { ErrorInfo(307); printf(" illegal power \'"); WriteTerm(t2); printf("\'.\n"); FreeAtomic(t1); FreeAtomic(t2); longjmp(alg1_jmp_buf,1); } pp=IntegerValue(t2); t1=ExpandTerm(t1); ret=CopyTerm(t1); for(i=2;i<=pp;i++) { Term tmp; tmp=CopyTerm(t1); ret=multiply_l(ret,tmp); } FreeAtomic(t1); return ret; } ErrorInfo(309); printf("bad expression "); WriteTerm(t); puts(""); longjmp(alg1_jmp_buf,1); }
void alg2_recommon_s(Term a2) { List m2l,l,la,l1; m2l=CompoundArgN(a2,5); l=m2l; if(is_empty_list(l)) return; la=CopyTerm(CompoundArg2(ListFirst(l))); l=ListTail(l); while(!is_empty_list(l)) { la=p_m_p_s(la,CompoundArg2(ListFirst(l))); l=ListTail(l); } l=la; while(!is_empty_list(l)) { if(IntegerValue(CompoundArg2(ListFirst(l)))==0 || (!(TexOutput||FAOutput) && GetAtomProperty(CompoundArg1(ListFirst(l)),A_DUMMY_PRM)) || (FAOutput && GetAtomProperty(CompoundArg1(ListFirst(l)), A_INFINITESIMAL)) ) { la=CutFromList(la,l); l=la; } else l=ListTail(l); } if(is_empty_list(la)) return; l1=ConsumeCompoundArg(a2,3); for(l=la;l;l=ListTail(l)) { List l2; for(l2=l1;l2;l2=ListTail(l2)) { if(CompoundArg1(ListFirst(l2))==CompoundArg1(ListFirst(l))) { int b1, b2; b1=IntegerValue(CompoundArg2(ListFirst(l))); b2=IntegerValue(CompoundArg2(ListFirst(l2))); b1+=b2; if(b1==0) l1=CutFromList(l1,l2); else SetCompoundArg(ListFirst(l2),2,NewInteger(b1)); break; } } if(is_empty_list(l2)) l1=AppendFirst(l1,CopyTerm(ListFirst(l))); } l1=SortedList(l1,prtcmp); SetCompoundArg(a2,3,l1); l=m2l; while(!is_empty_list(l)) { Term t; List l2,l3; t=ListFirst(l); l1=ConsumeCompoundArg(t,2); l2=la; while(!is_empty_list(l2)) { Term t2; t2=ListFirst(l2); l3=l1; while(!is_empty_list(l3)) { Term t3; t3=ListFirst(l3); if(CompoundArg1(t2)==CompoundArg1(t3)) { int np; np=IntegerValue(CompoundArg2(t3))-IntegerValue(CompoundArg2(t2)); if(np) { SetCompoundArg(t3,2,NewInteger(np)); goto l2cnt; } else { l1=CutFromList(l1,l3); goto l2cnt; } } l3=ListTail(l3); } l1=AppendLast(l1,MakeCompound2(OPR_POW,CompoundArg1(t2), NewInteger(-IntegerValue(CompoundArg2(t2))))); /*puts("Internal error: csm failed");*/ l2cnt: l2=ListTail(l2); } l1=SortedList(l1,prtcmp); SetCompoundArg(t,2,l1); l=ListTail(l); } FreeAtomic(la); }
static Term dif_term(Term t) { if(t==A_SQRT2 || t==A_I || is_float(t) || is_integer(t)) return 0; if(is_atom(t) && is_parameter(t)) return MakeCompound1(OPR_USCORE,t); if(!is_compound(t)) { printf("Can't variate "); WriteTerm(t); puts(""); return 0; } if(CompoundName(t)==OPR_PLUS && CompoundArity(t)==2) { Term d1,d2; d1=dif_term(CompoundArg1(t)); d2=dif_term(CompoundArg2(t)); if(d1==0 && d2==0) return 0; if(d1==0) return d2; if(d2==0) return d1; return MakeCompound2(OPR_PLUS,d1,d2); } if(CompoundName(t)==OPR_MINUS && CompoundArity(t)==2) { Term d1,d2; d1=dif_term(CompoundArg1(t)); d2=dif_term(CompoundArg2(t)); if(d1==0 && d2==0) return 0; if(d1==0) return d2; if(d2==0) return d1; return MakeCompound2(OPR_MINUS,d1,d2); } if(CompoundName(t)==OPR_MINUS && CompoundArity(t)==1) { Term d1; d1=dif_term(CompoundArg1(t)); if(d1==0) return 0; return MakeCompound1(OPR_MINUS,d1); } if(CompoundName(t)==A_SQRT && CompoundArity(t)==1) { Term d1; d1=dif_term(CompoundArg1(t)); if(d1==0) return 0; if(is_compound(d1) && CompoundName(d1)==OPR_MLT && CompoundArg1(d1)==NewInteger(2)) { Term d2; d2=ConsumeCompoundArg(d1,2); FreeAtomic(d1); return MakeCompound1(OPR_MINUS, MakeCompound2(OPR_DIV,d2,t)); } return MakeCompound1(OPR_MINUS, MakeCompound2(OPR_DIV, d1, MakeCompound2(OPR_MLT, NewInteger(2), t))); } if(CompoundName(t)==OPR_POW && CompoundArity(t)==2) { Term d1; int ppow; ppow=IntegerValue(CompoundArg2(t)); d1=dif_term(CompoundArg1(t)); if(d1==0) return 0; if(ppow==2) return MakeCompound2(OPR_MLT,NewInteger(2), MakeCompound2(OPR_MLT, CompoundArg1(t), d1)); return MakeCompound2(OPR_MLT, d1, MakeCompound2(OPR_POW, CompoundArg1(t),NewInteger(ppow-1))); } if(CompoundName(t)==OPR_MLT && CompoundArity(t)==2) { Term d1,d2; d1=dif_term(CompoundArg1(t)); d2=dif_term(CompoundArg2(t)); if(d1==0 && d2==0) return 0; if(d1==0) return MakeCompound2(OPR_MLT,CompoundArg1(t),d2); if(d2==0) return MakeCompound2(OPR_MLT,CompoundArg2(t),d1); return MakeCompound2(OPR_PLUS, MakeCompound2(OPR_MLT,CompoundArg1(t),d2), MakeCompound2(OPR_MLT,CompoundArg2(t),d1)); } if(CompoundName(t)==OPR_DIV && CompoundArity(t)==2) { Term d1,d2; d1=dif_term(CompoundArg1(t)); d2=dif_term(CompoundArg2(t)); if(d1==0 && d2==0) return 0; if(d1==0) return MakeCompound1(OPR_MINUS, MakeCompound2(OPR_DIV, MakeCompound2(OPR_MLT,d2,CompoundArg1(t)), MakeCompound2(OPR_POW,CompoundArg2(t),NewInteger(2)) ) ); if(d2==0) return MakeCompound2(OPR_DIV,d1,CompoundArg2(t)); return MakeCompound2(OPR_DIV, MakeCompound2(OPR_MINUS, MakeCompound2(OPR_MLT,d1,CompoundArg2(t)), MakeCompound2(OPR_MLT,d2,CompoundArg1(t)) ), MakeCompound2(OPR_POW,CompoundArg2(t),NewInteger(2)) ); } printf("Can't variate "); WriteTerm(t); puts(""); return 0; }
Term ProcMkProc(Term t, Term ind) { Atom prt[4]; Atom mass[4]; Term color[4]; int spin[4]; int i; int neufact=1; double thcut=0.0; int dec=0; char pname[128]; FILE *f; if(CompoundArity(t)==1) { List l,dlist; double m1; set_ppl(); l=GetAtomProperty(CompoundArg1(t),PROP_TYPE); if(!is_compound(l)||CompoundName(l)!=OPR_PARTICLE || CompoundArgN(l,5)==0) { ErrorInfo(0); WriteTerm(t); printf(" : decays are not generated.\n"); return 0; } m1=fabs(EvalParameter(CompoundArgN(l,5))); dlist=GetAtomProperty(CompoundArg1(t),PROP_PPL); for(l=dlist;l;l=ListTail(l)) { List pl=ListFirst(l); Atom prp,a; Atom ap1, ap2; double m2,m3; int is_neut; if(ListLength(pl)!=2) continue; prp=GetAtomProperty(ListFirst(pl),PROP_TYPE); if(!is_compound(prp)||CompoundName(prp)!=OPR_PARTICLE) continue; if(CompoundArgN(prp,7)==OPR_MLT) continue; a=CompoundArgN(prp,5); if(a==0) continue; else m2=fabs(EvalParameter(a)); prp=GetAtomProperty(ListFirst(ListTail(pl)),PROP_TYPE); if(!is_compound(prp)||CompoundName(prp)!=OPR_PARTICLE) continue; if(CompoundArgN(prp,7)==OPR_MLT) continue; a=CompoundArgN(prp,5); if(a==0) continue; else m3=fabs(EvalParameter(a)); if(m1<=m2+m3) continue; is_neut=(CompoundArg1(t)==GetAtomProperty(CompoundArg1(t),A_ANTI)); ap1=GetAtomProperty(ListFirst(pl),A_ANTI); ap2=GetAtomProperty(ListFirst(ListTail(pl)),A_ANTI); if(is_neut) { List l1; for(l1=dlist;l1!=l;l1=ListTail(l1)) { if( (ListFirst(ListFirst(l1))==ap1 && ListFirst(ListTail(ListFirst(l1)))==ap2) || (ListFirst(ListFirst(l1))==ap2 && ListFirst(ListTail(ListFirst(l1)))==ap1)) break; } if(l1!=l) continue; } /*WriteTerm(CompoundArg1(t));printf(" -> "); WriteTerm(pl);puts("");*/ prp=MakeCompound(A_I,4); SetCompoundArg(prp,1,CompoundArg1(t)); SetCompoundArg(prp,2,NewInteger(0)); SetCompoundArg(prp,3,is_neut?ListFirst(pl):ap1); SetCompoundArg(prp,4,is_neut?ListFirst(ListTail(pl)):ap2); ProcMkProc(prp,0); } return 0; } if(CompoundArity(t)<4) { ErrorInfo(2000); puts("mkProc: wrong argument number."); return 0; } for(i=5;i<=CompoundArity(t);i++) { Term t1=CompoundArgN(t,i); if(is_compound(t1) && is_atom(CompoundArg1(t1)) && strcmp(AtomValue(CompoundArg1(t1)),"THETACUT")==0) { if(is_integer(CompoundArg2(t1))) thcut=IntegerValue(CompoundArg2(t1)); else if(is_float(CompoundArg2(t1))) thcut=FloatValue(CompoundArg2(t1)); else { ErrorInfo(303);puts("wrong THETACUT value."); continue; } continue; } ErrorInfo(304); puts("wrong argument in mkProc."); } for(i=0;i<4;i++) { Term prp, t7; prt[i]=CompoundArgN(t,i+1); if(prt[i]==NewInteger(0)&&i==1) { dec=1;spin[i]=0;color[1]=0; continue; } if(!is_particle(prt[i],NULL)) { ErrorInfo(2001); WriteTerm(prt[i]); puts(": is not a particle."); return 0; } prp=GetAtomProperty(prt[i],PROP_TYPE); if(CompoundName(prp)!=OPR_PARTICLE) { ErrorInfo(2001); WriteTerm(prt[i]); puts(": is not a particle."); return 0; } if(prt[i]==CompoundArg2(prp)) prp=GetAtomProperty(CompoundArg1(prp),PROP_TYPE); spin[i]=IntegerValue(CompoundArgN(prp,4)); mass[i]=CompoundArgN(prp,5); color[i]=GetAtomProperty(prt[i],A_COLOR); t7=CompoundArgN(prp,7); if(i<2 && (t7==A_LEFT||t7==A_RIGHT)) neufact*=2; } if(dec==0) sprintf(pname,"%s%s__%s%s",AtomValue(prt[0]),AtomValue(prt[1]), AtomValue(prt[2]),AtomValue(prt[3])); else sprintf(pname,"%s__%s%s",AtomValue(prt[0]), AtomValue(prt[2]),AtomValue(prt[3])); for(i=0;pname[i];i++) { if(pname[i]=='~') pname[i]='_'; if(pname[i]=='+') pname[i]='p'; if(pname[i]=='-') pname[i]='m'; } f=fopen("scan.bat",inifile?"a":"w"); if(f==NULL) { ErrorInfo(2000); puts("mkProc: can not open scan.bat"); return 0; } if(!inifile) { fprintf(f,"#!/bin/sh\n\n"); inifile=1; } fprintf(f,"echo Generating process %s `date`\n\n",pname); fprintf(f,"echo Process %s: >> scan.log\n",pname); fprintf(f,"num0=`date +%%s`\n"); fprintf(f,"cat > proc.m <<END\n"); if(dec==0) fprintf(f,"process = {prt[\"%s\"],prt[\"%s\"]} ->", AtomValue(prt[0]),AtomValue(prt[1])); else fprintf(f,"process = {prt[\"%s\"]} ->", AtomValue(prt[0])); fprintf(f," {prt[\"%s\"],prt[\"%s\"]}\n", AtomValue(prt[2]),AtomValue(prt[3])); if(FAver==4) fprintf(f,"dir = SetupCodeDir[\"scan_%s\"]\n",pname); if(FAver>4) fprintf(f,"name = \"%s\"\n",pname); fprintf(f,"SetOptions[InsertFields,Model->model%d, GenericModel->model%d,\n", ModelNumber,ModelNumber); fprintf(f," ExcludeParticles->{ "); if(color[0]&&color[1]&&color[2]&&color[3]) { int glu=1,gno=1; if(GetAtomProperty(prt[0],A_ANTI)!=prt[1]) glu=0; if(spin[0]==0&&spin[1]==0&&spin[2]==0&&spin[3]==0) gno=0; if(glu) fprintf(f,"prt[\"G\"]%c ",gno?',':' '); if(gno) fprintf(f,"prt[\"~%c\"] ",ModelNumber>30?'G':'g'); } fprintf(f,"} ]\n"); fprintf(f,"END\n\n"); fprintf(f,"if test ! -d scan_%s/squaredme ;\n",pname); fprintf(f,"then math < %s.m;\n",dec?"scand":"scan"); fprintf(f,"fi\n\n"); fprintf(f,"num1=$((`date +%%s`-num0))\nnum0=`date +%%s`\n\n"); fprintf(f,"if test ! -d scan_%s/squaredme ;\n",pname); fprintf(f,"then echo Output directory is not created | tee -a scan.log && exit;\n"); fprintf(f,"fi\n\n"); fprintf(f,"if test ! -d drivers/F ;\n"); fprintf(f,"then cat > scan_%s/process.h <<END\n",pname); for(i=1;i<=4;i++) { int i1=i; if(dec&&i==2) continue; if(dec&&i>2) i1=i-1; fprintf(f,"#define TYPE%d %s\n",i1, spin[i-1]==0?"SCALAR":(spin[i-1]==1?"FERMION": (mass[i-1]==0?"PHOTON":"VECTOR"))); fprintf(f,"#define MASS%d %s\n",i1,mass[i-1]?AtomValue(mass[i-1]):"0"); fprintf(f,"#define CHARGE%d 0\n\n",i1); } fprintf(f,"#define IDENTICALFACTOR %s\n",(prt[2]==prt[3])?"0.5":"1"); fprintf(f,"#define COLOURFACTOR %dD0",neufact); if(color[0] && color[1]) fprintf(f,"/9D0"); else if(color[0] || color[1]) fprintf(f,"/3D0"); fprintf(f,"\n"); if(FAver>4) {fprintf(f,"#define SCALE sqrtS\n#define LUMI \"lumi_parton.F\"\n"); fprintf(f,"c#define FORCE_ONSHELL\n"); } fprintf(f,"#define NCOMP 2\n#include \"%cto2.F\"\nEND\n\nfi\n\n",dec?'1':'2'); /* fprintf(f,"cp model%d.h scan_%s/model.h\n",ModelNumber,pname); fprintf(f,"cp mdl_ini%d.F scan_%s/mdl_ini.F\n\n",ModelNumber,pname); */ if(FAver==4) fprintf(f,"cp main.F scan_%s/\n\n",pname); if(thcut!=0.0) { fprintf(f,"echo \"#define THETACUT (%f*degree)\" > scan_%s/run.F\n", thcut,pname); fprintf(f,"grep -v THETACUT drivers/run.F >> scan_%s/run.F\n",pname); } fprintf(f,"cd scan_%s\n",pname); fprintf(f,"sz0=`du -sm .`\n"); fprintf(f,"if test ! -f run ;\n"); fprintf(f,"then ./configure ;\n"); fprintf(f,"fi\n\n"); fprintf(f,"rm run ru*.01000*/*\n"); fprintf(f,"gmake\n"); fprintf(f,"if test ! -f run ;\n"); fprintf(f,"then echo Run file is not created | tee -a ../scan.log && exit;\n"); fprintf(f,"fi\n"); fprintf(f,"num2=$((`date +%%s`-num0))\nnum0=`date +%%s`\n\n"); fprintf(f,"sz1=`du -sm .`\n"); fprintf(f,"./run uuuu 1000,1000\n"); if(FAver>4) fprintf(f,"../exval6 ru*.01000*/* >> ../scan.log\n\n\n"); fprintf(f,"cd ..\n"); // fprintf(f,"grep \"| 1000.000\" scan_%s/ru*.01000*/* >> scan.log\n\n\n", // pname); if(FAver==4) fprintf(f,"./exval scan_%s/ru*.01000*/* >> scan.log\n\n\n",pname); fprintf(f,"num3=$((`date +%%s`-num0))\n\n"); fprintf(f,"echo $num1 + $num2 + $num3 = $(((num1+num2+num3)/60))"); fprintf(f," min \\\n $sz0/$sz1 MB >> scan.log\n"); fprintf(f,"rm -rf scan_%s\n\n",pname); fclose(f); return 0; }
Term alg1_inv_alg(Term a1) { List l, l1, lm; Term m2_b, m2_b2; List m2_i; l=CompoundArg1(a1); if(CompoundArg2(a1)) return 0; m2_i=m2_b=0; for(l1=l;l1;l1=ListTail(l1)) { Term m1; List l2; int ino; ino=0; m1=ListFirst(l1); for(l2=CompoundArgN(m1,3);l2;l2=ListTail(l2)) { Term prp=0; if(CompoundName(ListFirst(l2))==OPR_PARAMETER) prp=GetAtomProperty(CompoundArg2(ListFirst(l2)),A_INFINITESIMAL); else { RemoveList(m2_i); return 0; } if(prp && IntegerValue(CompoundArg1(prp))>0) ino+=IntegerValue(CompoundArg1(prp)); } if(!ino) { if(m2_b) { RemoveList(m2_i); return 0; } m2_b=m1; } else m2_i=AppendLast(m2_i,m1); } if(m2_b==0) return 0; m2_b=CopyTerm(m2_b); l=ConsumeCompoundArg(m2_b,3); l1=ConsumeCompoundArg(m2_b,4); SetCompoundArg(m2_b,3,l1); SetCompoundArg(m2_b,4,l); { int n, ns, d, ds; n=IntegerValue(CompoundArg1(m2_b)); d=IntegerValue(CompoundArg2(m2_b)); ns=ds=1; if(n<0) { ns=-1; n=-n; } if(d<0) { ds=-1; d=-d; } SetCompoundArg(m2_b,1,NewInteger(d*ns)); SetCompoundArg(m2_b,2,NewInteger(n*ds)); } lm=AppendLast(NewList(),m2_b); if(m2_i) { m2_b2=CopyTerm(m2_b); l=ConsumeCompoundArg(m2_b2,3); l=ConcatList(l,CopyTerm(l)); SetCompoundArg(m2_b2,3,l); l=ConsumeCompoundArg(m2_b2,4); l=ConcatList(l,CopyTerm(l)); SetCompoundArg(m2_b2,4,l); { int n,d,n1,d1; n=IntegerValue(CompoundArg1(m2_b2)); d=IntegerValue(CompoundArg2(m2_b2)); c_mlt(n,d,-n,d,&n1,&d1); SetCompoundArg(m2_b2,1,NewInteger(n1)); SetCompoundArg(m2_b2,2,NewInteger(d1)); } for(l=m2_i;l;l=ListTail(l)) { Term a1; a1=MakeCompound(A_MTERM,4); l1=ConcatList(CopyTerm(CompoundArgN(m2_b2,3)), CopyTerm(CompoundArgN(ListFirst(l),3))); SetCompoundArg(a1,3,l1); l1=ConcatList(CopyTerm(CompoundArgN(m2_b2,4)), CopyTerm(CompoundArgN(ListFirst(l),4))); SetCompoundArg(a1,4,l1); { int n,d; c_mlt( IntegerValue(CompoundArg1(m2_b2)), IntegerValue(CompoundArg2(m2_b2)), IntegerValue(CompoundArg1(ListFirst(l))), IntegerValue(CompoundArg2(ListFirst(l))), &n,&d); SetCompoundArg(a1,1,NewInteger(n)); SetCompoundArg(a1,2,NewInteger(d)); } lm=AppendLast(lm,a1); } RemoveList(m2_i); FreeAtomic(m2_b2); } /* DumpList(lm);*/ return MakeCompound2(A_ALG1,lm,0); }