复现了这篇论文的代码,上传分享,欢迎沟通交流

首先在routing目录下创建一个routing类,我的是SprophetRouting
代码如下:

public class SprophetRouter extends ActiveRouter {//只加了两个函数--BufferOccupyRatio()和 D_compute()--在最后面(319行往后)--改了那个相遇概率函数(126行)和衰减函数(186行)private double BE;//节点剩余缓存率private double D;//剩余缓存率对转发概率的影响因子private double D_init=1;private Map<DTNHost, Double> Bes;//建立列表存储BE值private double MSD;//没有实现-消息生存度值--消息的TTL剩余率/消息进入节点缓存的时长/** delivery predictability initialization constant*/public static final double P_INIT = 0.75;/** delivery predictability transitivity scaling constant default value */public static final double DEFAULT_BETA = 0.25;/** delivery predictability aging constant */public static final double GAMMA = 0.98;/** Prophet router's setting namespace ({@value})*/ public static final String PROPHET_NS = "SprophetRouter";/*** Number of seconds in time unit -setting id ({@value}).* How many seconds one time unit is when calculating aging of * delivery predictions. Should be tweaked for the scenario.*/public static final String SECONDS_IN_UNIT_S ="secondsInTimeUnit";/*** Transitivity scaling constant (beta) -setting id ({@value}).* Default value for setting is {@link #DEFAULT_BETA}.*/public static final String BETA_S = "beta";/** the value of nrof seconds in time unit -setting */private int secondsInTimeUnit;/** value of beta setting */private double beta;/** delivery predictabilities */private Map<DTNHost, Double> preds;/** last delivery predictability update (sim)time */private double lastAgeUpdate;/*** Constructor. Creates a new message router based on the settings in* the given Settings object.* @param s The settings object*/public SprophetRouter(Settings s) {super(s);Settings prophetSettings = new Settings(PROPHET_NS);secondsInTimeUnit = prophetSettings.getInt(SECONDS_IN_UNIT_S);if (prophetSettings.contains(BETA_S)) {beta = prophetSettings.getDouble(BETA_S);}else {beta = DEFAULT_BETA;}initPreds();initBEs();//初始化BEs表}/*** Copyconstructor.* @param r The router prototype where setting values are copied from*/protected SprophetRouter(SprophetRouter r) {super(r);this.secondsInTimeUnit = r.secondsInTimeUnit;this.beta = r.beta;initPreds();initBEs();//初始化BEs表}/*** Initializes predictability hash*/private void initPreds() {this.preds = new HashMap<DTNHost, Double>();}@Overridepublic void changedConnection(Connection con) {super.changedConnection(con);if (con.isUp()) {DTNHost otherHost = con.getOtherNode(getHost());updateDeliveryPredFor(otherHost);updateTransitivePreds(otherHost);updateBEs();}}/*** Updates delivery predictions for a host.* <CODE>P(a,b) = P(a,b)_old + (1 - P(a,b)_old) * P_INIT</CODE>* @param host The host we just met*/private void updateDeliveryPredFor(DTNHost host) {double oldValue = getPredFor(host);double newValue = oldValue + (1 - oldValue) * P_INIT *D_compute(host);//乘上增加的D因子preds.put(host, newValue);Bes.put(host,GetHostBE(host));}/*** Returns the current prediction (P) value for a host or 0 if entry for* the host doesn't exist.* @param host The host to look the P for* @return the current P value*/public double getPredFor(DTNHost host) {ageDeliveryPreds(); // make sure preds are updated before gettingif (preds.containsKey(host)) {return preds.get(host);}else {return 0;}}/*** Updates transitive (A->B->C) delivery predictions.* <CODE>P(a,c) = P(a,c)_old + (1 - P(a,c)_old) * P(a,b) * P(b,c) * BETA* </CODE>* @param host The B host who we just met*/private void updateTransitivePreds(DTNHost host) {MessageRouter otherRouter = host.getRouter();assert otherRouter instanceof SprophetRouter : "PRoPHET only works " + " with other routers of same type";double pForHost = getPredFor(host); // P(a,b)Map<DTNHost, Double> othersPreds = ((SprophetRouter)otherRouter).getDeliveryPreds();for (Map.Entry<DTNHost, Double> e : othersPreds.entrySet()) {if (e.getKey() == getHost()) {continue; // don't add yourself}double pOld = getPredFor(e.getKey()); // P(a,c)_olddouble pNew = pOld + ( 1 - pOld) * pForHost * e.getValue() * beta;preds.put(e.getKey(), pNew);}}/*** Ages all entries in the delivery predictions.* <CODE>P(a,b) = P(a,b)_old * (GAMMA ^ k)</CODE>, where k is number of* time units that have elapsed since the last time the metric was aged.* @see #SECONDS_IN_UNIT_S*/private void ageDeliveryPreds() {double timeDiff = (SimClock.getTime() - this.lastAgeUpdate) / secondsInTimeUnit;if (timeDiff == 0) {return;}double mult = Math.pow(GAMMA, timeDiff*(1-GetBE()));//但是这里的源代码也用了pow函数,timeDiff如果为浮点数,也会被转化为整数?这里我只是多乘了*(1-BE)for (Map.Entry<DTNHost, Double> e : preds.entrySet()) {e.setValue(e.getValue()*mult);}this.lastAgeUpdate = SimClock.getTime();}/*** Returns a map of this router's delivery predictions* @return a map of this router's delivery predictions*/private Map<DTNHost, Double> getDeliveryPreds() {ageDeliveryPreds(); // make sure the aging is donereturn this.preds;}@Overridepublic void update() {super.update();if (!canStartTransfer() ||isTransferring()) {return; // nothing to transfer or is currently transferring }// try messages that could be delivered to final recipientif (exchangeDeliverableMessages() != null) {return;}tryOtherMessages();       }/*** Tries to send all other messages to all connected hosts ordered by* their delivery probability* @return The return value of {@link #tryMessagesForConnected(List)}*/private Tuple<Message, Connection> tryOtherMessages() {List<Tuple<Message, Connection>> messages = new ArrayList<Tuple<Message, Connection>>(); Collection<Message> msgCollection = getMessageCollection();/* for all connected hosts collect all messages that have a higherprobability of delivery by the other host */for (Connection con : getConnections()) {DTNHost other = con.getOtherNode(getHost());SprophetRouter othRouter = (SprophetRouter)other.getRouter();if (othRouter.isTransferring()) {continue; // skip hosts that are transferring}for (Message m : msgCollection) {if (othRouter.hasMessage(m.getId())) {continue; // skip messages that the other one has}if (othRouter.getPredFor(m.getTo()) > getPredFor(m.getTo())) {// the other node has higher probability of delivery//进行be的判断,假设高中低分界线是0.01和0.25,ρ1为0.3,ρ2为0.6if(this.BE<=0.8&&(getDeliveryBes().get(other)>=0.25)){//第一种情况,自身中低对方高if(othRouter.getPredFor(m.getTo())<0.3) {continue;}}else if((getDeliveryBes().get(other))<0.3){//第二种情况,对方低if(othRouter.getPredFor(m.getTo())<0.6) {continue;}}messages.add(new Tuple<Message, Connection>(m,con));//发送消息给另一节点}}           }if (messages.size() == 0) {return null;}// sort the message-connection tuplesCollections.sort(messages, new TupleComparator());return tryMessagesForConnected(messages); // try to send messages}/*** Comparator for Message-Connection-Tuples that orders the tuples by* their delivery probability by the host on the other side of the * connection (GRTRMax)*/private class TupleComparator implements Comparator <Tuple<Message, Connection>> {public int compare(Tuple<Message, Connection> tuple1,Tuple<Message, Connection> tuple2) {// delivery probability of tuple1's message with tuple1's connectiondouble p1 = ((SprophetRouter)tuple1.getValue().getOtherNode(getHost()).getRouter()).getPredFor(tuple1.getKey().getTo());// -"- tuple2...double p2 = ((SprophetRouter)tuple2.getValue().getOtherNode(getHost()).getRouter()).getPredFor(tuple2.getKey().getTo());// bigger probability should come firstif (p2-p1 == 0) {/* equal probabilities -> let queue mode decide */return compareByQueueMode(tuple1.getKey(), tuple2.getKey());}else if (p2-p1 < 0) {return -1;}else {return 1;}}}@Overridepublic RoutingInfo getRoutingInfo() {ageDeliveryPreds();RoutingInfo top = super.getRoutingInfo();RoutingInfo ri = new RoutingInfo(preds.size() + " delivery prediction(s)");for (Map.Entry<DTNHost, Double> e : preds.entrySet()) {DTNHost host = e.getKey();Double value = e.getValue();ri.addMoreInfo(new RoutingInfo(String.format("%s : %.6f", host, value)));}top.addMoreInfo(ri);return top;}@Overridepublic MessageRouter replicate() {SprophetRouter r = new SprophetRouter(this);return r;}//只加了两个函数--BufferOccupyRatio()和 D_compute()如下//BE剩余缓存率public double GetBE(){BE=(getFreeBufferSize())/getBufferSize();return BE;}public double GetHostBE(DTNHost host) {SprophetRouter r = (SprophetRouter)host.getRouter();double b = r.GetBE();return b;}public double D_compute(DTNHost host){double b = GetHostBE(host);D=D_init+((1-b)*(1-P_INIT))/P_INIT;D = Math.pow(D,b);return D;}/***初始化BEs列表  */private void initBEs() {this.Bes = new HashMap<DTNHost, Double>();}public double GetBefor(DTNHost host){updateBEs();if (Bes.containsKey(host)) {return Bes.get(host);}else {Bes.put(host,GetHostBE(host));return GetHostBE(host);}}//更新besprivate void updateBEs() {double timeDiff = (SimClock.getTime() - this.lastAgeUpdate) / secondsInTimeUnit;if (timeDiff == 0) {return;}for (Map.Entry<DTNHost, Double> e : Bes.entrySet()) {DTNHost other = e.getKey();SprophetRouter r = (SprophetRouter)other.getRouter();e.setValue(r.GetBE());}this.lastAgeUpdate = SimClock.getTime();}private Map<DTNHost, Double> getDeliveryBes() {updateBEs(); // 更新return this.Bes;}@Overrideprotected Message getNextMessageToRemove(boolean excludeMsgBeingSent) {Collection<Message> messages = this.getMessageCollection();Message lastMSD = null;for (Message m : messages) {   if (excludeMsgBeingSent && isSending(m.getId())) {continue; // skip the message(s) that router is sending}if(lastMSD == null) {lastMSD = m;}else if(lastMSD.getMSD()>m.getMSD()) {lastMSD = m;}}return lastMSD;}@Overridepublic Message messageTransferred(String id, DTNHost from) {//from是发送消息的节点Message m = super.messageTransferred(id, from);if(from.getRouter().hasMessage(m.getId())) {if(this.getPredFor(m.getTo()) > 0.7) {//假设上面messages已经成功发送给另一节点,现在进行当前节点的判断,是否大于Pth,Pth暂定为0.7from.getRouter().deleteMessage(m.getId(), false);}}return m;}
}

在Message.java中加入get_MSD方法:

 public double getMSD() {double Rttl = (this.initTtl-((SimClock.getTime()-this.timeCreated)/60))/(this.initTtl);double Tb = SimClock.getTime()-this.getReceiveTime();double MSD = Rttl/Tb;return MSD;}//专为Sprophet设置,可删除;

作者邮箱:1821862797@qq.com

one平台 复现代码 节点缓存感知的DTN概率路由算法相关推荐

  1. m认知无线电网络中频谱感知的按需路由算法matlab仿真

    目录 1.算法概述 2.仿真效果预览 3.MATLAB部分代码预览 4.完整MATLAB程序 1.算法概述 使用无线电用户的频率范围在 9kHz 到 275GHz[3],由于无线通信环境中的干扰.信道 ...

  2. 利用九天深度学习平台复现SSA-GAN

    目录 一.算力领取 1.1.领取算力 二.复现SSA-GAN 2.1.创建实例 2.2.下载代码和数据集 2.3.下载预训练的 DAMSM 模型 2.4.环境配置 2.5.训练 最后 Semantic ...

  3. Net平台下的分布式缓存设计

    缓存真是个好东西,在大型的系统中可以有效地提升系统的速度,此乃废话就不多说了,在.Net 平台下面我把缓存从功用大致分为两类,数据对象缓存和页面输出缓存.对于数据缓存来讲是由System.Web.Ca ...

  4. Gitee 答疑:为什么从 Gitee 平台 Pull 代码到 STS/Eclipse 后文件乱码?逐步排查

    文章目录 前言 一.产生乱码场景 1.1.错误描述 1.2.解决思路 二.解决方式 2.1.检查 Git 平台上的源码 2.2.Git 的运行原理 2.3.修改 IDE 的文本编码格式 2.4.重新打 ...

  5. 【Android 逆向】代码调试器开发 ( 使用 NDK 中的 ndk-build + Android.mk 编译 Android 平台的代码调试器可执行应用 )

    文章目录 一.Android 平台代码调试器代码 二.Android.mk 构建脚本内容 三.Application.mk 构建脚本内容 四.正式编译 五.博客资源 一.Android 平台代码调试器 ...

  6. 【CV】YOLOv4最全复现代码合集(含PyTorch/TF/Keras和Caffe等)

    前言 2020年4月24日,CVer第一时间推文:大神接棒,YOLOv4来了! 2020年6月28日,CVer第一时间推文:YOLOv4-Tiny来了!371 FPS! 距离YOLOv4正式推出,已经 ...

  7. YOLOv3最全复现代码合集(含PyTorch/TensorFlow和Keras等)

    点击上方"CVer",选择"置顶公众号" 重磅干货,第一时间送达 前戏 2018年3月26日,CVer第一时间推文:YOLOv3:你一定不能错过 2019年3月 ...

  8. android+微信一键关注,一键关注微信公众平台JS代码有哪些?

    一键关注微信公众平台JS代码有哪些?在网页设置一个按钮或者链接可以让用户一键关注微信公众平台,那么这种一键关注微信公众平台的功能如何实现呢?下面小编分享给大家一键关注微信公众平台的JS代码. 在微信上 ...

  9. ios html清除缓存,iOS开发之1行代码实现缓存计算及清除缓存

    话不多说,直接撸代码 // // gzhCache.h // cache // // Created by 郭志贺 on 2020/5/27. // Copyright © 2020 郭志贺. All ...

最新文章

  1. 二值网络--XNOR-Net: ImageNet Classification Using Binary Convolutional Neural Networks
  2. FFmpeg command line tool(Android中使用FFmpeg命令行)
  3. Extjs4:改变Grid单元格背景色(转载)
  4. sublime_text快捷键
  5. 《我们不一样》团队项目用户验收评审
  6. C#事件(event)解析(转)
  7. linux内核驱动子系统,linux内核中的MFD子系统
  8. 3元购买微信小程序解决方案一个月
  9. PHP获取一篇文章内容中的全部图片,并下载
  10. 雪花算法生成一个id
  11. journalctl命令
  12. 双网卡服务器实现内外网访问
  13. 数据中台实战入门篇:双中台战略
  14. 群晖DSM7添加套件源
  15. 第五节 FLASH 程序存储器和数据EEPROM
  16. Win10防火墙放行MySQL3306端口
  17. 5.3. Constraints
  18. 什么是宝塔面板?宝塔面板的作用和功能是什么?
  19. 通向财务自由之路04_设定你的目标
  20. 介绍 Go 断续器(Tickers)

热门文章

  1. 【阅读笔记】End-to-End Learning for RIS-Aided Communication Systems
  2. 《CCIE路由和交换认证考试指南(第5版) (第2卷)》——1.3节构建BGP表
  3. vue中禁止页面滚动/滚动事件穿透-弹出蒙版时弹出层下面还可以滚动问题解决
  4. 在电脑上怎样将图片转成Word?
  5. Machine learning(ML)常用的几类学习器及Python实现
  6. Abp vNext DTO国际化
  7. 一秒钟世界上会发生多少事_全球迎第26次闰秒 一秒钟能干多少事?
  8. 对于FlowNet3D论文代码的理解(pointnet++)
  9. Linux 虚拟机联网 connect: Network is unreachable
  10. 在Hadoop核心组件中,我愿称 YARN 为最强!(附源码)