tictoc例子理解 16-18

news2024/10/2 10:32:53

tictoc16-18

    • tictoc 16 全局信号signal
    • tictoc 17 在仿真界面幕布上显示总条数信息
    • tictoc 18

tictoc 16 全局信号signal

  1. 前一步的主要问题是,如果我们想要更改所收集的统计信息,就必须修改模型的代码。统计计算深入到模型代码中,很难修改和理解。
  2. omnet++ 4.1提供了一种叫做“信号”的不同机制,我们可以用它来收集统计数据。
  3. 首先,我们必须识别模型状态发生变化的事件。我们可以在这些点上发射带有所选状态变量值的信号。
  4. 通过这种方式,c++代码只发出信号,但是如何处理这些信号仅由附加到它们的侦听器决定。
  5. 模型发出的信号和处理它们的侦听器可以使用’signal’和’statistic’属性在NED文件中定义。
  6. 我们将收集与上一步相同的统计信息,但请注意,我们不需要任何私有成员变量来计算这些值。我们将只使用一个信号,该信号在消息到达时发出,并在消息中携带hopcount。
  7. arrivalSignal = registerSignal("arrival");返回给定信号名称的信号ID。信号名称和id是全局的。特定名称的信号ID在第一次registerSignal()调用时被分配;对相同名称的进一步registerSignal()调用将返回相同的ID。注意:自从omnet++ 4.3以来,信号注册表在运行之间不会被清除,所以可以使用静态初始化来分配全局simsignal_t变量:
    msg
message TicTocMsg16
{
    int source;
    int destination;
    int hopCount = 0;
}

ned

simple Txc16
{
    parameters:
        @signal[arrival](type="long");//long型变量
        @statistic[hopCount](title="hop count"; source="arrival"; record=vector,stats; interpolationmode=none);
        
        @display("i=block/routing");
    gates:
        inout gate[];
}

network Tictoc16
{
    types:
        channel Channel extends ned.DelayChannel {
            delay = 100ms;
        }
    submodules:
        tic[6]: Txc16;
    connections:
        tic[0].gate++ <--> Channel <--> tic[1].gate++;
        tic[1].gate++ <--> Channel <--> tic[2].gate++;
        tic[1].gate++ <--> Channel <--> tic[4].gate++;
        tic[3].gate++ <--> Channel <--> tic[4].gate++;
        tic[4].gate++ <--> Channel <--> tic[5].gate++;
}

cc

#include <stdio.h>
#include <string.h>
#include <omnetpp.h>
#include "tictoc16_m.h"

using namespace omnetpp;

/**
 * The main problem with the previous step is that we must modify the model's
 * code if we want to change what statistics are gathered. Statistic calculation
 * is woven deeply into the model code which is hard to modify and understand.
 *
 * OMNeT++ 4.1 provides a different mechanism called 'signals' that we can use
 * to gather statistics. First we have to identify the events where the state
 * of the model changes. We can emit signals at these points that carry the value
 * of chosen state variables. This way the C++ code only emits signals, but how those
 * signals are processed are determined only by the listeners that are attached to them.
 *
 * The signals the model emits and the listeners that process them can be defined in
 * the NED file using the 'signal' and 'statistic' property.
 *
 * We will gather the same statistics as in the previous step, but notice that we will not need
 * any private member variables to calculate these values. We will use only a single signal that
 * is emitted when a message arrives and carries the hopcount in the message.
 * 前一步的主要问题是,如果我们想要更改所收集的统计信息,就必须修改模型的代码。统计计算深入到模型代码中,很难修改和理解。

omnet++ 4.1提供了一种叫做“信号”的不同机制,我们可以用它来收集统计数据。首先,我们必须识别模型状态发生变化的事件。我们可以在这些点上发射带有所选状态变量值的信号。通过这种方式,c++代码只发出信号,但是如何处理这些信号仅由附加到它们的侦听器决定。

模型发出的信号和处理它们的侦听器可以使用'signal'和'statistic'属性在NED文件中定义。

我们将收集与上一步相同的统计信息,但请注意,我们不需要任何私有成员变量来计算这些值。我们将只使用一个信号,该信号在消息到达时发出,并在消息中携带hopcount。
 */
class Txc16 : public cSimpleModule
{
  private:
    simsignal_t arrivalSignal;

  protected:
    virtual TicTocMsg16 *generateMessage();
    virtual void forwardMessage(TicTocMsg16 *msg);
    virtual void initialize() override;
    virtual void handleMessage(cMessage *msg) override;
};

Define_Module(Txc16);

void Txc16::initialize()
{
    arrivalSignal = registerSignal("arrival");//返回信号的名称和ID
    // Module 0 sends the first message
    if (getIndex() == 0) {
        // Boot the process scheduling the initial message as a self-message.
        TicTocMsg16 *msg = generateMessage();
        scheduleAt(0.0, msg);
    }
}

void Txc16::handleMessage(cMessage *msg)
{
    TicTocMsg16 *ttmsg = check_and_cast<TicTocMsg16 *>(msg);

    if (ttmsg->getDestination() == getIndex()) {
        // Message arrived
        int hopcount = ttmsg->getHopCount();
        // send a signal 发出一个号
        emit(arrivalSignal, hopcount);

        EV << "Message " << ttmsg << " arrived after " << hopcount << " hops.\n";
        bubble("ARRIVED, starting new one!");

        delete ttmsg;

        // Generate another one.
        EV << "Generating another message: ";
        TicTocMsg16 *newmsg = generateMessage();
        EV << newmsg << endl;
        forwardMessage(newmsg);
    }
    else {
        // We need to forward the message.
        forwardMessage(ttmsg);
    }
}

TicTocMsg16 *Txc16::generateMessage()
{
    // Produce source and destination addresses.
    int src = getIndex();
    int n = getVectorSize();
    int dest = intuniform(0, n-2);
    if (dest >= src)
        dest++;

    char msgname[20];
    sprintf(msgname, "tic-%d-to-%d", src, dest);

    // Create message object and set source and destination field.
    TicTocMsg16 *msg = new TicTocMsg16(msgname);
    msg->setSource(src);
    msg->setDestination(dest);
    return msg;
}

void Txc16::forwardMessage(TicTocMsg16 *msg)
{
    // Increment hop count.
    msg->setHopCount(msg->getHopCount()+1);

    // Same routing as before: random gate.
    int n = gateSize("gate");
    int k = intuniform(0, n-1);

    EV << "Forwarding message " << msg << " on gate[" << k << "]\n";
    send(msg, "gate$o", k);
}

tictoc 17 在仿真界面幕布上显示总条数信息

  1. 仿真幕布显示内容:
@figure[description](type=text; pos=5,20; font=,,bold; 
        	text="Random routing example - displaying last hop count");
        @figure[lasthopcount](type=text; pos=5,35; text="last hopCount: N/A");

msg略
ned

simple Txc17
{
    parameters:
        @signal[arrival](type="long");
        @statistic[hopCount](title="hop count"; source="arrival"; record=vector,stats; interpolationmode=none);

        @display("i=block/routing");
    gates:
        inout gate[];
}

network Tictoc17
{
    parameters:
        @figure[description](type=text; pos=5,20; font=,,bold; 
        	text="Random routing example - displaying last hop count");
        @figure[lasthopcount](type=text; pos=5,35; text="last hopCount: N/A");
    types:
        channel Channel extends ned.DelayChannel {
            delay = 100ms;
        }
    submodules:
        tic[6]: Txc17;
    connections:
        tic[0].gate++ <--> Channel <--> tic[1].gate++;
        tic[1].gate++ <--> Channel <--> tic[2].gate++;
        tic[1].gate++ <--> Channel <--> tic[4].gate++;
        tic[3].gate++ <--> Channel <--> tic[4].gate++;
        tic[4].gate++ <--> Channel <--> tic[5].gate++;
}

cc

#include <stdio.h>
#include <string.h>
#include <omnetpp.h>
#include "tictoc17_m.h"

using namespace omnetpp;

class Txc17 : public cSimpleModule
{
private:
    simsignal_t arrivalSignal;

protected:
    virtual TicTocMsg17 *generateMessage();
    virtual void forwardMessage(TicTocMsg17 *msg);
    virtual void initialize() override;
    virtual void handleMessage(cMessage *msg) override;
};

Define_Module(Txc17);

void Txc17::initialize()
{
    arrivalSignal = registerSignal("arrival");
    // Module 0 sends the first message
    if (getIndex() == 0) {
        // Boot the process scheduling the initial message as a self-message.
        TicTocMsg17 *msg = generateMessage();
        scheduleAt(0.0, msg);
    }
}

void Txc17::handleMessage(cMessage *msg)
{
    TicTocMsg17 *ttmsg = check_and_cast<TicTocMsg17 *>(msg);

    if (ttmsg->getDestination() == getIndex()) {
        // Message arrived
        int hopcount = ttmsg->getHopCount();
        // send a signal
        emit(arrivalSignal, hopcount);

        if (hasGUI()) {
            char label[50];
            // Write last hop count to string
            sprintf(label, "last hopCount = %d", hopcount);
            // Get pointer to figure
            cCanvas *canvas = getParentModule()->getCanvas();
            cTextFigure *textFigure = check_and_cast<cTextFigure*>(canvas->getFigure("lasthopcount"));
            // Update figure text
            textFigure->setText(label);
        }

        EV << "Message " << ttmsg << " arrived after " << hopcount << " hops.\n";
        bubble("ARRIVED, starting new one!");

        delete ttmsg;

        // Generate another one.
        EV << "Generating another message: ";
        TicTocMsg17 *newmsg = generateMessage();
        EV << newmsg << endl;
        forwardMessage(newmsg);
    }
    else {
        // We need to forward the message.
        forwardMessage(ttmsg);
    }
}

TicTocMsg17 *Txc17::generateMessage()
{
    // Produce source and destination addresses.
    int src = getIndex();
    int n = getVectorSize();
    int dest = intuniform(0, n-2);
    if (dest >= src)
        dest++;

    char msgname[20];
    sprintf(msgname, "tic-%d-to-%d", src, dest);

    // Create message object and set source and destination field.
    TicTocMsg17 *msg = new TicTocMsg17(msgname);
    msg->setSource(src);
    msg->setDestination(dest);
    return msg;
}

void Txc17::forwardMessage(TicTocMsg17 *msg)
{
    // Increment hop count.
    msg->setHopCount(msg->getHopCount()+1);

    // Same routing as before: random gate.
    int n = gateSize("gate");
    int k = intuniform(0, n-1);

    EV << "Forwarding message " << msg << " on gate[" << k << "]\n";
    send(msg, "gate$o", k);
}

在这里插入图片描述

tictoc 18

  1. 前一步的主要问题是,如果我们想要更改所收集的统计信息,就必须修改模型的代码。统计计算深入到模型代码中,很难修改和理解。
  2. omnet++ 4.1提供了一种叫做“信号”的不同机制,我们可以用它来收集统计数据。首先,我们必须识别模型状态发生变化的事件。我们可以在这些点上发射带有所选状态变量值的信号。通过这种方式,c++代码只发出信号,但是如何处理这些信号仅由附加到它们的侦听器决定。
  3. 模型发出的信号和处理它们的侦听器可以使用’signal’和’statistic’属性在NED文件中定义。
  4. 我们将收集与上一步相同的统计信息,但请注意,我们不需要任何私有成员变量来计算这些值。我们将只使用一个信号,该信号在消息到达时发出,并在消息中携带hopcount。
    msg略
    ned
simple Txc18 extends Txc16
{
}

network TicToc18
{
    parameters:
        int numCentralNodes = default(2);
    types:
        channel Channel extends ned.DelayChannel {
            delay = 100ms;
        }
    submodules:
        tic[numCentralNodes+4]: Txc18;
    connections:
        // connect the 2 nodes in one side to the central nodes
        tic[0].gate++ <--> Channel <--> tic[2].gate++;
        tic[1].gate++ <--> Channel <--> tic[2].gate++;
        // connect the central nodes together将中心节点连接在一起
        for i=2..numCentralNodes+1 {
            tic[i].gate++ <--> Channel <--> tic[i+1].gate++;
        }
        // connect the 2 nodes on the other side to the central nodes
        tic[numCentralNodes+2].gate++ <--> Channel <--> tic[numCentralNodes+1].gate++;
        tic[numCentralNodes+3].gate++ <--> Channel <--> tic[numCentralNodes+1].gate++;
}

cc

#include <stdio.h>
#include <string.h>
#include <omnetpp.h>
#include "tictoc18_m.h"

using namespace omnetpp;

/**
 * The main problem with the previous step is that we must modify the model's
 * code if we want to change what statistics are gathered. Statistic calculation
 * is woven deeply into the model code which is hard to modify and understand.
 *
 * OMNeT++ 4.1 provides a different mechanism called 'signals' that we can use
 * to gather statistics. First we have to identify the events where the state
 * of the model changes. We can emit signals at these points that carry the value
 * of chosen state variables. This way the C++ code only emits signals, but how those
 * signals are processed are determined only by the listeners that are attached to them.
 *
 * The signals the model emits and the listeners that process them can be defined in
 * the NED file using the 'signal' and 'statistic' property.
 *
 * We will gather the same statistics as in the previous step, but notice that we will not need
 * any private member variables to calculate these values. We will use only a single signal that
 * is emitted when a message arrives and carries the hopcount in the message.
 * 前一步的主要问题是,如果我们想要更改所收集的统计信息,就必须修改模型的代码。统计计算深入到模型代码中,很难修改和理解。

omnet++ 4.1提供了一种叫做“信号”的不同机制,我们可以用它来收集统计数据。首先,我们必须识别模型状态发生变化的事件。我们可以在这些点上发射带有所选状态变量值的信号。通过这种方式,c++代码只发出信号,但是如何处理这些信号仅由附加到它们的侦听器决定。

模型发出的信号和处理它们的侦听器可以使用'signal'和'statistic'属性在NED文件中定义。

我们将收集与上一步相同的统计信息,但请注意,我们不需要任何私有成员变量来计算这些值。我们将只使用一个信号,该信号在消息到达时发出,并在消息中携带hopcount。
 */
class Txc18 : public cSimpleModule
{
  private:
    simsignal_t arrivalSignal;

  protected:
    virtual TicTocMsg18 *generateMessage();
    virtual void forwardMessage(TicTocMsg18 *msg);
    virtual void initialize() override;
    virtual void handleMessage(cMessage *msg) override;
};

Define_Module(Txc18);

void Txc18::initialize()
{
    arrivalSignal = registerSignal("arrival");
    // Module 0 sends the first message
    if (getIndex() == 0) {
        // Boot the process scheduling the initial message as a self-message.
        TicTocMsg18 *msg = generateMessage();
        scheduleAt(0.0, msg);
    }
}

void Txc18::handleMessage(cMessage *msg)
{
    TicTocMsg18 *ttmsg = check_and_cast<TicTocMsg18 *>(msg);

    if (ttmsg->getDestination() == getIndex()) {
        // Message arrived
        int hopcount = ttmsg->getHopCount();
        // send a signal
        emit(arrivalSignal, hopcount);

        EV << "Message " << ttmsg << " arrived after " << hopcount << " hops.\n";
        bubble("ARRIVED, starting new one!");

        delete ttmsg;

        // Generate another one.
        EV << "Generating another message: ";
        TicTocMsg18 *newmsg = generateMessage();
        EV << newmsg << endl;
        forwardMessage(newmsg);
    }
    else {
        // We need to forward the message.
        forwardMessage(ttmsg);
    }
}

TicTocMsg18 *Txc18::generateMessage()
{
    // Produce source and destination addresses.
    int src = getIndex();
    int n = getVectorSize();
    int dest = intuniform(0, n-2);
    if (dest >= src)
        dest++;

    char msgname[20];
    sprintf(msgname, "tic-%d-to-%d", src, dest);

    // Create message object and set source and destination field.
    TicTocMsg18 *msg = new TicTocMsg18(msgname);
    msg->setSource(src);
    msg->setDestination(dest);
    return msg;
}

void Txc18::forwardMessage(TicTocMsg18 *msg)
{
    // Increment hop count.
    msg->setHopCount(msg->getHopCount()+1);

    // Same routing as before: random gate.
    int n = gateSize("gate");
    int k = intuniform(0, n-1);

    EV << "Forwarding message " << msg << " on gate[" << k << "]\n";
    send(msg, "gate$o", k);
}


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/54431.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

大型扫码点餐小程序系统源码

1. 开发语言&#xff1a;JAVA 2. 数据库&#xff1a;MySQL 3. 原生小程序 4. Sass 模式 5. 带调试视频 6. 可付费调试服务 扫码点餐小程序管理端&#xff1a; 数据统计&#xff1a;今日订单、堂食、预约、外卖、储值 堂食订单&#xff1a;订单号、商家、门店、类型、会员、桌位…

Spring进阶(二十)之事件处理

目录 为什么需要使用事件这种模式 事件模式中的几个概念 使用事件模式实现上面用户注册的业务 事件对象 事件监听器 事件广播器 事件广播默认实现 自定义用户注册成功事件类 用户注册服务 下面我们使用spring来将上面的对象组装起来 测试用例模拟用户注册 添加注册…

第四十篇 Vue封装swiper组件(v-swiper指令) 3.0

在前面讲到 Vue组件的封装不知道还记不记得&#xff0c;这里就不在过多的赘述&#xff0c;这里附上链接跳转可以进行回顾翻阅&#xff0c;上一篇内容​​​​​​​讲到这个自定义的指令&#xff0c;也就是为这篇封装swiper组件使用指令做铺垫的&#xff0c;那么也一同附在这里…

电子电气架构设计之三电系统设计

文中缩略词参考 SSTS&#xff1a;Sub System Technical Specification&#xff0c;子系统功能规范 CTS&#xff1a;Component Technical Specification&#xff0c;部件功能规范 DCDC&#xff1a;Direct Current Direct Current Converter&#xff0c;直流转直流变换器 BMS&…

Postgresql源码(92)深入分析HOT更新

0 概述与总结 hot更新已经有几篇分析了&#xff0c;这里是最后一篇&#xff08;总结性的&#xff0c;前面的可以忽略&#xff09;。前面在看update代码时&#xff0c;大部分集中在heap_update上&#xff0c;没有涉及寻找HOT链的逻辑。本篇重点看HOT链是如何使用的。 &#xf…

[附源码]计算机毕业设计JAVA鑫地酒店酒水库存管理系统论文

[附源码]计算机毕业设计JAVA鑫地酒店酒水库存管理系统论文 项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; …

搜索技术——群智能

如果有兴趣了解更多相关内容&#xff0c;欢迎来我的个人网站看看&#xff1a;瞳孔空间 一&#xff1a;初识群智能 1.1&#xff1a;粒子群算法 粒子群算法&#xff0c;也称粒子群优化算法或鸟群觅食算法&#xff08;Particle Swarm Optimization&#xff09;&#xff0c;缩写…

语音特征:spectrogram、Fbank(fiterbank)、MFCC

1.各种语音特征 语音特征用于语音识别和语音合成等。 语音特征有声谱图spectrogram、Fbank(fiterbank)、MFCC(Mel-frequency cepstral coefficients)等。 Fbank 特征提取方法就是相当 于 MFCC 去掉最后一步的离散余弦变换&#xff08;有损变换&#xff09;. 在深度学习之前…

git学习笔记

1、安装及配置git 1、到官网下载git安装包&#xff1a;https://git-scm.com/download/win 2、安装完成后&#xff0c;菜单栏有如下工具 3、配置账户和邮件信息 $ git config --global user.name "xxx"$ git config --global user.email "xxxmegvii.com"4…

十大排序算法(C++)

十大排序算法Sorting algorithm(C) 百度百科&#xff1a; 所谓排序&#xff0c;就是使一串记录&#xff0c;按照其中的某个或某些关键字的大小&#xff0c;递增或递减的排列起来的操作。排序算法&#xff0c;就是如何使得记录按照要求排列的方法。排序算法在很多领域得到相当地…

高通平台开发系列讲解(AI篇)如何让yolov5运行在SNPE

文章目录 一、模型下载二、模型转换三、模型量化四、后处理加速沉淀、分享、成长,让自己和他人都能有所收获!😄 📢本篇章主要介绍高通平台SNPE SDK运行yolov5。 一、模型下载 首先去git上下载yolov5s的代码和模型https://github.com/ultralytics/yolov5 二、模型转换 采…

Python爬虫实战,requests+xlwings模块,Python实现制作天气预报表!

前言 今天为大家介绍PythonExcel的实战项目&#xff0c;非常有趣&#xff0c;废话不多说。 Let’s start happily 开发工具 Python版本&#xff1a; 3.6.4 相关模块&#xff1a; xlwings模块 requests模块 pathlib模块 xlwings模块 json模块 环境搭建 安装Python并…

RAR压缩包,去除密码?

压缩包设置了加密&#xff0c;需要输入压缩包密码才能够顺利解压文件出来。但是有些时候&#xff0c;一些文件只需要一段时间内要加密&#xff0c;之后文件不需要加密了&#xff0c;每次解压文件的时候还是需要输入压缩包密码才行&#xff0c;就很麻烦&#xff0c;那么RAR压缩包…

SAP 接口主动推送企业微信异常消息

"推送企业微信格式lv_json { "msgtype": "markdown", "markdown": &&{ "content": "### 异常JOB通知\n >JOB名称&#xff1a; && gt_alv-jobname && \n 程序名称&#xff1a; && gt_…

戟星安全实验室|五分钟教你挖掘小程序漏洞

戟星安全实验室 忆享科技旗下高端的网络安全攻防服务团队.安服内容包括渗透测试、代码审计、应急响应、漏洞研究、威胁情报、安全运维、攻防演练等。 本文约1252字&#xff0c;阅读约需5分钟。 前言 现在大多小程序反编译教程所使用的都是node.js&#xff0c;操作过程较为麻烦…

第一周练习——认识复杂度和简单排序算法

前言&#xff1a; &#x1f44f;作者简介&#xff1a;我是笑霸final&#xff0c;一名热爱技术的在校学生。 &#x1f4dd;个人主页&#xff1a;个人主页1 || 笑霸final的主页2 &#x1f4d5;系列专栏&#xff1a;《数据结构与算法》 &#x1f4e7;如果文章知识点有错误的地方&a…

Mediapipe学习记录

学习文档 1、Google MediaPipe&#xff1a;设备端机器学习【完整解决方案】背后的技术实现 - 极术社区 - 连接开发者与智能计算生态 2、【转载】Google MediaPipe&#xff1a;设备端机器学习【完整解决方案】背后的技术实现 3、MediaPipe框架结构 - 走看看 Handtracking封装…

qt creator 设置 项目依赖关系

qt creator中有两种设置项目依赖关系的方式。 1、对于有依赖的项目&#xff0c;如果工程比较简单&#xff0c;可以将所有项目放到一个空的项目下&#xff0c;然后显示地指定从属关系&#xff0c;参考&#xff1a;qmake TEMPLATE subdirs_丘上人的博客-CSDN博客 2、通过qt cre…

leecode#Excel表列序号#组合两个表

题目描述&#xff1a; 给你一个字符串 columnTitle &#xff0c;表示 Excel 表格中的列名称。返回 该列名称对应的列序号 。 分析&#xff1a; 法1&#xff0c;进制转换 这道题要求将Excel 表中的列名称转换成相对应的列序号。由于Excel 表的列名称由大写字母组成&#xff…

vue学习53~60(Vue组件化编程)

2 Vue组件化编程 2.1 模块与组件、模块化与组件化 2.1.1 模块 理解:向外提供特定功能的js程序,一般就是一 个js文件为什么: js 文件很多很复杂作用:复用js,简化js的编写,提高js运行效率 2.1.2 组件 理解:用来实现局部(特定)功能效果的代码集合(html/css/js/image…)为什么…