tictoc例子理解10-13

news/2024/5/6 16:56:06/文章来源:https://blog.csdn.net/qq_41550190/article/details/128109995

tictoc10-13

    • tictoc 10 几个模块连接,发送消息直到模块3收到消息
    • tictoc 11 新增信道定义
    • tictoc 12 双向连接信息简化定义

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 gatesoutput 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 gatesoutput 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 gatesend(msg, "gate$o", k);
}

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

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ANR 触发、监控、分析 一网打尽

平时看博客或者学知识&#xff0c;学到的东西比较零散&#xff0c;没有独立的知识模块概念&#xff0c;而且学了之后很容易忘。于是我建立了一个自己的笔记仓库 (一个我长期维护的笔记仓库&#xff0c;感兴趣的可以点个star~你的star是我写作的巨大大大大的动力)&#xff0c;将…

大客车玻璃擦净器设计

目 录 摘 要 I ABSTRACT II 1 绪论 1 1.1选题背景及意义 1 1.2发展现状 2 1.3发展趋势 3 1.4研究主要内容 4 2 大客车玻璃擦净器总体方案设计 5 2.1 大客车玻璃擦净器设计思想 5 2.2功能分析 5 2.3工作原理分析 6 2.4功能分解 6 2.4.2传动系统 6 2.4.3真空吸盘 7 2.4.4 清洁刷 …

欢聚季报图解:营收5.87亿美元同比降10% 净利提升

雷递网 雷建平 11月29日欢聚集团(NASDAQ: YY)今日发布2022年第三季度财报。财报显示&#xff0c;欢聚集团2022年第三季度营收为5.867亿美元&#xff0c;较上年同期下降10%。欢聚集团2022年第三季度Bigo Live的平均移动MAU为3540万&#xff0c;较上年同期的3100万增长14.2%&…

转铁蛋白修饰的去氢骆驼蓬碱磁纳米脂质体TF-HM-MPS

转铁蛋白又名运铁蛋白&#xff08;Transferrin&#xff0c;TRF、Tf&#xff09;&#xff0c;负责运载由消化管吸收的铁和由红细胞降解释放的铁。以三价铁复合物&#xff08;Tf-Fe3&#xff09;的形式进入骨髓中&#xff0c;供成熟红细胞的生成。转铁蛋白主要存在于血浆中&#…

冒烟测试的7个好处,你是否经常用到它?

以下为作者观点&#xff1a; 冒烟测试(smoke testing)是在开发的早期阶段评估基本的软件组件&#xff0c;以检查它们是否 “着火”&#xff08;有问题&#xff09;&#xff0c;本文旨在介绍冒烟测试及其在程序开发过程中的作用。 什么是冒烟测试&#xff1f; 冒烟测试是在开…

企业日常公关如何抵御负面信息的入侵?

如今&#xff0c;互联网时代信息传播速度极快&#xff0c;这使得宣传工作效率倍增&#xff0c;也给企业舆情管理带来一定的挑战。舆情优化搞得好&#xff0c;企业宣传工作事半功倍&#xff0c;网络舆论走向负面的话&#xff0c;则对宣传工作非常不利&#xff0c;会导致推广效果…

狂神说Go语言学习笔记(一)

一、Go语言的发展史 二、Go语言能做什么 三、Go语言环境安装 下载地址 国外网站太慢&#xff0c;我们使用中文网进行下载&#xff01; Go下载 - Go语言中文网 - Golang中文社区 (studygolang.com) 安装 无脑下一步就完了 &#xff0c;注意下这里创建自己设置一个Go语言的环…

比搞笑诺奖还离谱,看完国产AIGC最新创作,把我给整不会了

杨净 萧箫 发自 凹非寺量子位 | 公众号 QbitAI现在&#xff0c;AI生成的东西&#xff0c;“真实”得都让我有点害怕了——只是给出《马斯克获得诺贝尔物理学奖》这个标题&#xff0c;AI竟然就刷刷刷几下&#xff0c;蹦出了一整套大纲来&#xff1f;&#xff01;如果让AI生成一些…

计算机网络——分层结构,协议接口,服务

分层结构 主机进行资源共享时需满足以下条件&#xff1a; &#xff08;1&#xff09;发起通信的计算机要将数据通路进行激活 &#xff08;2&#xff09;告诉网络如何识别主机 &#xff08;3&#xff09;发起通信的主机要查明目的主机是否开机等 &#xff08;4&#xff09;发起…

【Linux】权限讲解

一、什么是权限 1、权限概念 权限随处可见&#xff0c;在生活中&#xff0c;腾讯非VIP用户不能观看VIP视频&#xff0c;看小说也需要会员&#xff0c;所以权限是限制人的&#xff0c;一件事是否允许被谁做。在Linux系统中也有许多权限&#xff0c;访问文件需要权限&#xff0c…

Windows OpenGL 图像色彩替换

目录 一.OpenGL 图像色彩替换 1.原始图片2.效果演示 二.OpenGL 图像色彩替换源码下载三.猜你喜欢 零基础 OpenGL ES 学习路线推荐 : OpenGL ES 学习目录 >> OpenGL ES 基础 零基础 OpenGL ES 学习路线推荐 : OpenGL ES 学习目录 >> OpenGL ES 特效 零基础 OpenGL…

[附源码]Python计算机毕业设计Django的实验填报管理系统

项目运行 环境配置&#xff1a; Pychram社区版 python3.7.7 Mysql5.7 HBuilderXlist pipNavicat11Djangonodejs。 项目技术&#xff1a; django python Vue 等等组成&#xff0c;B/S模式 pychram管理等等。 环境需要 1.运行环境&#xff1a;最好是python3.7.7&#xff0c;我…

FastDFS文件上传

分布式文件存储-FastDFS 介绍 FastDFS为互联网量身定制&#xff0c;充分考虑了冗余备份、负载均衡、线性扩容等机制&#xff0c;并注重高可用、高性能等指标&#xff0c;使用FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传、下载等服务。 FastDFS体系结构 FastD…

基于改进粒子群算法的微电网多目标优化调度(Matlab代码实现)

&#x1f468;‍&#x1f393;个人主页&#xff1a;研学社的博客 &#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜…

62 - 单例类模板

---- 整理自狄泰软件唐佐林老师课程 1. 单例模式 1.1 需求的提出 在架构设计时&#xff0c;某些类 在整个系统生命期中 最多只能有一个对象存在&#xff08;Single Instance&#xff09; 1.1.1 问题 如何定义一个类&#xff0c;使得这个类最多只能创建一个对象&#xff1f;…

模拟电路设计(35)---几种脉宽调制型开关电路

Forward单端正激变换器 在buck变换器开关与负载之间插入隔离变压器&#xff0c;这种隔离型buck变换器叫做Forward单端正激变换器。如下图所示&#xff1a; Forward单端正激变换器 简单分析可知&#xff0c;滤波电感L在开关管关断期间&#xff0c;通过续流二极管为负载提供电流…

【手把手】教你玩转SpringCloud Alibaba之Nacos Config深入

1、不同环境相同配置问题-自定义Data ID配置 在实际的开发过程中&#xff0c;项目所用到的配置参数有的时候并不需要根据不同的环境进行区分&#xff0c;生产、测试、开发环境所用到的参数值是相同的。怎么解决同一服务在多环境中&#xff0c;引用相同的配置的问题&#xff1f…

Flutter 离线数据方案 Flutter_Data 包

Flutter 离线数据方案 Flutter_Data 包 原文 https://levelup.gitconnected.com/flutter-offline-first-with-flutter-data-62bad61097be 前言 通过离线优先来改善您的用户体验 Flutter Data 是一个让你的应用程序先离线的软件包。 离线时&#xff0c;它在设备上使用 Hive 存储…

H2N-Hyp-FF-OH, 2493080-84-3

Hyp-Phe-Phe 是一种三肽&#xff0c;通过 Phe 环的芳香相互作用形成螺旋状的薄片&#xff0c;构成一个交叉螺旋结构。Hyp-Phe-Phe 具有很高的剪切压电特性&#xff0c;可作为一种压电材料。Hyp-Phe-Phe is a tripeptide that forms helical-like sheets via aromatic interacti…

天翎知识文档系统+群晖NAS,助力企业实现移动化学习

编者按&#xff1a;移动化学习成为一种社会发展趋势&#xff0c;本文分析了企业移动化学习的意义&#xff0c;并提出了企业移动化学习的一款全新解决方案——天翎知识文档系统群晖NAS。 关键词&#xff1a;多端适配&#xff0c;学习培训&#xff0c;智能问答&#xff0c;在线预…