tictoc例子理解10-12

2023-11-04

tictoc 10 几个模块连接,发送消息直到模块3收到消息

  1. 让我们用几个(n)’ tic’模块让它更有趣,并将每个模块连接到其他模块。
  2. 把它们的工作简单化:模块0生成一条消息,其他模块继续向随机方向传递消息,直到它到达模块2。
    在这里插入图片描述
    ned
simple Txc10
{
    parameters:
        @display("i=block/routing");
    gates:
        input in[];  // declare in[] and out[] to be vector gates
        output out[];
}

network Tictoc10
{
    @display("bgb=226,176");
    submodules:
        tic[6]: Txc10 {
            @display("p=70,76");
        }
    connections:
        tic[0].out++ --> {  delay = 100ms; } --> tic[1].in++;
        tic[0].in++ <-- {  delay = 100ms; } <-- tic[1].out++;

        tic[1].out++ --> {  delay = 100ms; } --> tic[2].in++;
        tic[1].in++ <-- {  delay = 100ms; } <-- tic[2].out++;

        tic[1].out++ --> {  delay = 100ms; } --> tic[4].in++;
        tic[1].in++ <-- {  delay = 100ms; } <-- tic[4].out++;

        tic[3].out++ --> {  delay = 100ms; } --> tic[4].in++;
        tic[3].in++ <-- {  delay = 100ms; } <-- tic[4].out++;

        tic[4].out++ --> {  delay = 100ms; } --> tic[5].in++;
        tic[4].in++ <-- {  delay = 100ms; } <-- tic[5].out++;
}

cc

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

using namespace omnetpp;

/**
 * Let's make it more interesting by using several (n) `tic' modules,
 * and connecting every module to every other. For now, let's keep it
 * simple what they do: module 0 generates a message, and the others
 * keep tossing it around in random directions until it arrives at
 * module 2.
 * 让我们用几个(n)让它更有趣' tic'模块,并将每个模块连接到其他模块。现在,让我们把它们的工作简单化:模块0生成一条消息,其他模块继续向随机方向传递消息,直到它到达模块2。
 */
class Txc10 : public cSimpleModule
{
  protected:
    virtual void forwardMessage(cMessage *msg);
    virtual void initialize() override;
    virtual void handleMessage(cMessage *msg) override;
};

Define_Module(Txc10);

void Txc10::initialize()
{
    if (getIndex() == 0) {
        // Boot the process scheduling the initial message as a self-message.启动,将初始消息调度为自消息的进程。
        char msgname[20];
        sprintf(msgname, "tic-%d", getIndex());
        cMessage *msg = new cMessage(msgname);
        scheduleAt(0.0, msg);
    }
}

void Txc10::handleMessage(cMessage *msg)
{
    if (getIndex() == 3) {
        // Message arrived.
        EV << "Message " << msg << " arrived.\n";
        delete msg;
    }
    else {
        // We need to forward the message.
        forwardMessage(msg);
    }
}

void Txc10::forwardMessage(cMessage *msg)
{
    // In this example, we just pick a random gate to send it on.
    // We draw a random number between 0 and the size of gate `out[]'.
    int n = gateSize("out");
    int k = intuniform(0, n-1);

    EV << "Forwarding message " << msg << " on port out[" << k << "]\n";
    send(msg, "out", k);
}

在这里插入图片描述

tictoc 11 新增信道定义

  1. (实现内容同上)让我们用几个(n)’ tic’模块让它更有趣,并将每个模块连接到其他模块。现在,让我们把它们的工作简单化:模块0生成一条消息,其他模块继续向随机方向传递消息,直到它到达模块2。
  2. 信道使用本地信道类型定义,减少连接冗余
types://定义信道
        channel Channel extends ned.DelayChannel {
            delay = 100ms;
        }

ned

simple Txc11
{
    parameters:
        @display("i=block/routing");
    gates:
        input in[];  // declare in[] and out[] to be vector gates
        output out[];
}


//
// Using local channel type definition to reduce the redundancy
// of connection definitions.
//
//使用本地通道类型定义来减少连接定义的冗余。
network Tictoc11
{
    types://定义信道
        channel Channel extends ned.DelayChannel {
            delay = 100ms;
        }
    submodules:
        tic[6]: Txc11;
    connections:
        tic[0].out++ --> Channel --> tic[1].in++;
        tic[0].in++ <-- Channel <-- tic[1].out++;

        tic[1].out++ --> Channel --> tic[2].in++;
        tic[1].in++ <-- Channel <-- tic[2].out++;

        tic[1].out++ --> Channel --> tic[4].in++;
        tic[1].in++ <-- Channel <-- tic[4].out++;

        tic[3].out++ --> Channel --> tic[4].in++;
        tic[3].in++ <-- Channel <-- tic[4].out++;

        tic[4].out++ --> Channel --> tic[5].in++;
        tic[4].in++ <-- Channel <-- tic[5].out++;
}

cc

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

using namespace omnetpp;

/**
 * Let's make it more interesting by using several (n) `tic' modules,
 * and connecting every module to every other. For now, let's keep it
 * simple what they do: module 0 generates a message, and the others
 * keep tossing it around in random directions until it arrives at
 * module 2.
 * 让我们用几个(n)让它更有趣' tic'模块,并将每个模块连接到其他模块。
 * 现在,让我们把它们的工作简单化:
 * 模块0生成一条消息,其他模块继续向随机方向传递消息,直到它到达模块2。
 */
class Txc11 : public cSimpleModule
{
  protected:
    virtual void forwardMessage(cMessage *msg);
    virtual void initialize() override;
    virtual void handleMessage(cMessage *msg) override;
};

Define_Module(Txc11);

void Txc11::initialize()
{
    if (getIndex() == 0) {
        // Boot the process scheduling the initial message as a self-message.
        char msgname[20];
        sprintf(msgname, "tic-%d", getIndex());
        cMessage *msg = new cMessage(msgname);
        scheduleAt(0.0, msg);
    }
}

void Txc11::handleMessage(cMessage *msg)
{
    if (getIndex() == 3) {
        // Message arrived.
        EV << "Message " << msg << " arrived.\n";
        delete msg;
    }
    else {
        // We need to forward the message.
        forwardMessage(msg);
    }
}

void Txc11::forwardMessage(cMessage *msg)
{
    // In this example, we just pick a random gate to send it on.
    // We draw a random number between 0 and the size of gate `out[]'.
    int n = gateSize("out");
    int k = intuniform(0, n-1);

    EV << "Forwarding message " << msg << " on port out[" << k << "]\n";
    send(msg, "out", k);
}

在这里插入图片描述
在这里插入图片描述

tictoc 12 双向连接信息简化定义

  1. 使用双向连接进一步简化网络定义
    ned
simple Txc12
{
    parameters:
        @display("i=block/routing");
    gates:
        inout gate[];  // declare two way connections 声明双向连接
}

// using two way connections to further simplify the network definition
//使用双向连接进一步简化网络定义
network Tictoc12
{
    types:
        channel Channel extends ned.DelayChannel {
            delay = 100ms;
        }
    submodules:
        tic[6]: Txc12;
    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>

using namespace omnetpp;

/**
 * Let's make it more interesting by using several (n) `tic' modules,
 * and connecting every module to every other. For now, let's keep it
 * simple what they do: module 0 generates a message, and the others
 * keep tossing it around in random directions until it arrives at
 * module 2.
 */
class Txc12 : public cSimpleModule
{
  protected:
    virtual void forwardMessage(cMessage *msg);
    virtual void initialize() override;
    virtual void handleMessage(cMessage *msg) override;
};

Define_Module(Txc12);

void Txc12::initialize()
{
    if (getIndex() == 0) {
        // Boot the process scheduling the initial message as a self-message.
        char msgname[20];
        sprintf(msgname, "tic-%d", getIndex());
        cMessage *msg = new cMessage(msgname);
        scheduleAt(0.0, msg);
    }
}

void Txc12::handleMessage(cMessage *msg)
{
    if (getIndex() == 3) {
        // Message arrived.
        EV << "Message " << msg << " arrived.\n";
        delete msg;
    }
    else {
        // We need to forward the message.
        forwardMessage(msg);
    }
}

void Txc12::forwardMessage(cMessage *msg)
{
    // In this example, we just pick a random gate to send it on.
    // We draw a random number between 0 and the size of gate `gate[]'.
    int n = gateSize("gate");
    int k = intuniform(0, n-1);

    EV << "Forwarding message " << msg << " on gate[" << k << "]\n";
    // $o and $i suffix is used to identify the input/output part of a two way gate
    send(msg, "gate$o", k);
}


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

tictoc例子理解10-12 的相关文章

  • 与 for_each 或 std::transform 一起使用时,如何调用 C++ 函子构造函数

    我以前从未使用过 C 函子 所以我只是想了解它们是如何工作的 例如假设我们有这个函子类 class MultiplyBy private int factor public MultiplyBy int x factor x int ope
  • 格式说明符%02x

    我有一个简单的程序 include
  • 是否需要销毁运算符删除的形式才能真正销毁对象?

    C 20 添加了破坏形式operator delete区别于std destroying delete t范围 它导致delete表达式在调用之前不再销毁对象operator delete 目的是在显式调用对象的析构函数和释放内存之前 允许
  • 捕获 .aspx 和 .ascx 页面中的异常

    问题说明了一切 请看以下示例代码 ul li li ul
  • 如何使用 openSSL 函数验证 PEM 证书的密钥长度

    如何验证以这种方式生成的 PEM 证书的密钥长度 openssl genrsa des3 out server key 1024 openssl req new key server key out server csr cp server
  • EntityHydrate 任务失败

    我最近安装了 Visual Studio 11 Beta 和 Visual Studio 2010 之后 我无法在 Visual Studio 2010 中构建依赖于 PostSharp 的项目 因此我卸载了 Visual Studio 1
  • Boost ASIO 串行写入十六进制值

    我正在使用 ubuntu 通过串行端口与设备进行通信 所有消息都必须是十六进制值 我已经在 Windows 环境中使用白蚁测试了通信设置 并得到了我期望的响应 但在使用 Boost asio 时我无法得到任何响应 以下是我设置串口的方法 b
  • 2个对象,完全相同(除了命名空间)c#

    我正在使用第三方的一组网络服务 但遇到了一个小障碍 在我手动创建将每个属性从源复制到目标的方法之前 我想我应该在这里寻求更好的解决方案 我有 2 个对象 一个是 Customer CustomerParty 类型 另一个是 Appointm
  • 如何修复错误:“检测到无法访问的代码”

    我有以下代码 private string GetAnswer private int CountLeapYears DateTime startDate return count String answer GetAnswer Respo
  • 混合模型优先和代码优先

    我们使用模型优先方法创建了一个 Web 应用程序 一名新开发人员进入该项目 并使用代码优先方法 使用数据库文件 创建了一个新的自定义模型 这 这是代码第一个数据库上下文 namespace WVITDB DAL public class D
  • Android NDK 代码中的 SIGILL

    我在市场上有一个 NDK 应用程序 并获得了有关以下内容的本机崩溃报告 SIGILL信号 我使用 Google Breakpad 生成本机崩溃报告 以下是详细信息 我的应用程序是为armeabi v7a with霓虹灯支持 它在 NVIDI
  • 来自嵌入图像的 BitmapSource

    我的目标是在 WPF 窗口上重写 OnRender 方法中绘制图像 someImage png 它是嵌入资源 protected override void OnRender System Windows Media DrawingCont
  • LinkLabel 无下划线 - Compact Framework

    我正在使用 Microsoft Compact Framework 开发 Windows CE 应用程序 我必须使用 LinkLabel 它必须是白色且没有下划线 因此 在设计器中 我将字体颜色修改为白色 并在字体对话框中取消选中 下划线
  • 在 azure blob 存储中就地创建 zip 文件

    我将文件存储在 Blob 存储帐户内的一个容器中 我需要在第二个容器中创建一个 zip 文件 其中包含第一个容器中的文件 我有一个使用辅助角色和 DotNetZip 工作的解决方案 但由于 zip 文件的大小最终可能达到 1GB 我担心在进
  • SQLAPI++ 的免费替代品? [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 是否有任何免费 也许是开源 的替代品SQLAPI http www sqlapi com 这个库看起来
  • 使用 gcc 时在头文件中查找定义的好方法是什么?

    在使用 gcc 时 有人有推荐的方法在头文件中查找定义吗 使用 MSVC 时 我只需右键单击并选择 转到定义 这非常好 我使用过 netbeans gcc 它确实有代码帮助 包括到定义的超链接 所以这是一种选择 但是 我想知道是否有任何其他
  • 调用 .ToArray() 时出现 ArgumentException

    我有一个经常被清除的列表 代码完全是这样的 VisitorAgent toPersist List
  • 如何在C#中控制datagridview光标移动

    我希望 datagridview 光标向右移动到下一列 而不是在向单元格输入数据后移动到下一行 我试图通过 dataGridView1 KeyDown 事件捕获键来控制光标 但这并不能阻止光标在将数据输入到单元格后移动到下一行 提前感谢你的
  • C:设置变量范围内所有位的最有效方法

    让我们来int举个例子 int SetBitWithinRange const unsigned from const unsigned to To be implemented SetBitWithinRange应该返回一个int其中所有
  • 如何从 Windows Phone 7 模拟器获取数据

    我有一个 WP7 的单元测试框架 它在手机上运行 结果相当难以阅读 因此我将它们写入 XDocument 我的问题是 如何才能将这个 XML 文件从手机上移到我的桌面上 以便我可以实际分析结果 到目前为止 我所做的是将 Debugger B

随机推荐

  • Notepad++正则命令全解 -- 小黑超细详解

    notepad 为文本编辑器工具 是windows的一款免费开源工具 功能有很多吧 还可以运行脚本 倒是也没有具体去研究 不过用起来挺方便的 记录一下平常使用会用到的吧 下载 Notepad GitHub 目录 举一个栗子 简单使用正则 正
  • Qt中多个单选按钮信号连接到同一个槽函数

    当多个类似信号需要连接到同一个槽函数时 在槽函数内需要对信号的来源进行判断 这里主要是采用sender 函数 此函数会返回信号来源的方向 让我们来看看效果 接下来是具体的代码 首先添加3个RadioButton 并且连接到同一个槽函数 QS
  • 软件工程——第13章软件项目管理知识点整理(完结)

    本专栏是博主个人笔记 主要目的是利用碎片化的时间来记忆软工知识点 特此声明 文章目录 1 管理的定义 2 软件项目管理地位 重要性
  • 【自学开发之旅】Flask-restful-Jinjia页面编写template-回顾(五)

    restful是web编程里重要的概念 一种接口规范也是一种接口设计风格 设计接口 要考虑 数据返回 接收数据的方式 url 方法 统一风格 rest 表现层状态转移 web 每一类数据 资源 资源通过http的动作来实现状态转移 GET
  • iframe 相互获取值

    链接 https www cnblogs com henuyuxiang p 7427155 html
  • Hp 笔记本开机不进入 grub 引导 ubuntu与windows选择界面

    我在预装了 windows 的机器上安装 ubuntu 每次想启动 ubuntu 时都需要按下 F9 才能进入引导选择界面 使用 ubuntu 的 efibootmgr 和 boot repair 等工具都不起作用 只是改变了 ubuntu
  • git常规操作

    场景一 从项目A的dev分支复制到项目B的dev分支上 1 将项目B clone 到本地 git clone b master 项目B的git地址 2 将项目A的git地址 添加至本地的remote git remote add upstr
  • 每月摘录--2023年7月

    企业 证监会最新消息 对蚂蚁集团及旗下机构处以罚款 含没收违法所得 71 23 亿元 并要求蚂蚁集团关停违规开展的 相互宝 业务 并依法补偿消费者利益 极客公园 7 月 7 日消息 据央行公布的行政处罚信息显示 今日 财付通支付科技有限公司
  • CoordinatorLayout的简单使用,android开发app的详细过程

    效果展示 代码展示
  • 军工重组

    http bar stockstar com p8448439 1 html 下周可千万别洗出来 2660到现在用了没多久就临近3000点 只要地产一起来马上就到3600了 地产现在不涨并不是不想涨 而是只要地产一起来马上就到3600 多数
  • VSCode安装教程最新,包教包会!

    一 VScode下载 1 进入VScode官网 官网地址 https code visualstudio com 点击 Download 进入下载 不要点击 Download for Windows Stable Build 否则它会自动帮
  • 编译Linux内核生成Image和System.map文件

    p span style font family 华文楷体 font size 12pt background color rgb 255 255 255 一直想琢磨琢磨Linux内核 便开始看 Linux内核完全注释 可是发现一头雾水 所
  • 用java实现计算器四则运算以及混合运算

    贴代码 本例测试是基于junit eclipse可安装对应 的java包 我用的是idea 添加插件即可 import java io BufferedReader import java io IOException import jav
  • eclipse 配置 C++

    前言 最近有项目需要c 但是c 自从离校那时就没碰过了 所以要重新学习下 因为曾经为了做自己的博客网站 学了java 下载了eclipse 也是在eclipse上写的博客网站的 所以对eclipse还是相对熟悉的 而且平时写代码都是用vim
  • android手势识别opencv,较为成熟的安卓项目--人面识别,手势识别向

    一 人脸识别 1 目标检测 目标追踪 人脸检测 人脸识别 效果 2 Android下使用OpenCV实现人脸检测 效果 3 人脸标识 效果 4 人脸检测 github https github com VernonVan Face 效果 主
  • Jmeter 中随机函数__Random 的使用

    前段时间 在做接口测试时 经常遇到接口参数需要输入不同的内容或者手机号码等 不允许输入重复的参数内容 比如不同的手机号码 那此时可以通过Random 随机函数来解决此问题 以前的文章有介绍过使用time函数来实现 详见 http blog
  • RuntimeError: Error(s) in loading state_dict for Net(让人心累的错误)

    RuntimeError Error s in loading state dict for Net size mismatch for classifier 4 weight xxxxxx 后面一堆错误 这个是model py 千万千万别
  • 【DL】第 6 章:语言建模

    大家好 我是Sonhhxg 柒 希望你看完之后 能对你有所帮助 不足请指正 共同学习交流 个人主页 Sonhhxg 柒的博客 CSDN博客 欢迎各位 点赞 收藏 留言 系列专栏 机器学习 ML 自然语言处理 NLP 深度学习 DL fore
  • 小程序跳转:云开发之h5跳小程序

    目录 前言 前提条件 注意 实现步骤 更多前端知识 前言 此方案是我在实际开发中的全部过程 因为我也是第一次做小程序的云开发 一开始根据这个文档就遇到了一些坑 所以在这里我做了更详细的步骤分解 非个人主体并且已认证的 微信认证 小程序 使用
  • tictoc例子理解10-12

    tictoc10 12 tictoc 10 几个模块连接 发送消息直到模块3收到消息 tictoc 11 新增信道定义 tictoc 12 双向连接信息简化定义 tictoc 10 几个模块连接 发送消息直到模块3收到消息 让我们用几个 n