CloudSim中的实例之SimEvent

package org.cloudbus.cloudsim.core;

/* 在实体之间传递的仿真事件  */

public class SimEvent implements Cloneable,Comparable<SimEvent>{
    private final int etype;               //内部事件类型
    private final double time;             //事件发生时间
    private double endWaitingTime;         //事件从队列移除时间
    private int entSrc;                    //调度事件实体ID
    private int entDst;                 //事件将发送给实体的ID
    private final int tag;             //用户定义的事件类型
    private final Object data;         //事件携带数据
    private long serial=-1;            //???

    //内部事件类型
    public static final int ENULL=0;
    public static final int SEND=1;
    public static final int HOLD_DONE=2;
    public static final int CREATE=3;

    //默认构造函数
    public SimEvent(){
        etype=0;
        this.time=-1L;
        endWaitingTime=-1.0;
        entSrc=-1;
        entDst=-1;
        this.tag=-1;
        data=null;
    }

    //重载构造函数
    SimEvent(int evtype,double time,int src,int dest,int tag,Object edata){
        etype=evtype;
        this.time=time;
        entSrc=src;
        entDst=dest;
        this.tag=tag;
        data=edata;
    }

    //重载构造函数
    SimEvent(int evtype,double time,int src){
        etype=evtype;
        this.time=time;
        entSrc=src;
        entDst=-1;
        this.tag=-1;
        data=null;
    }

    protected void setSerial(long serial){
        this.serial=serial;
    }

    //设置事件在队列中等待完成时间
    protected void setEndWaitingTime(double end_waiting_time){
        this.endWaitingTime=end_waiting_time;
    }

    public String toString(){
        return "Event tag = "+tag+" source = "
                +CloudSim.getEntity(this.entSrc).getName()
                +" destination = "
                + CloudSim.getEntity(this.entDst).getName();
    }

    //内部类型
    public int getType(){
        return etype;
    }

    public int compareTo(SimEvent event){    //问题:比较有什么用??
        if(event==null){
            return 1;      //事件为空
        }else if(time<event.time){
            return -1;
        }else if(time>event.time){
            return 1;
        }else if(serial<event.serial){
            return -1;
        }else if(this==event){
            return 0;
        }else{
            return 1;
        }
    }

    //接收事件的实体ID
    public int getDestination(){
        return entDst;
    }

    //调度事件的实体ID
    public int getSource(){
        return entSrc;
    }

    //事件从队列移除的仿真时间
    public double endWaitingTime{
        return endWaitingTime;
    }

    //用户自定义的事件标签
    public int type(){
        return tag;
    }

    //调度事件的ID
    public int scheduledBy(){
        return entSrc;
    }

    //用户自定义的事件标签
    public int getTag(){
        return tag;
    }

    //事件中传递的数据
    public Object getData(){
        return data;
    }

    //准确复制事件
    public Object clone(){
        return new SimEvent(etype,time,entSrc,entDst,tag,data);
    }

    //事件来源实体
    public void setSource(int s){
        entSrc=s;
    }

    //事件目的实体
    public void setDestination(int d){
        entDst=d;
    }
}
时间: 2024-08-03 07:07:51

CloudSim中的实例之SimEvent的相关文章

Delphi中Tlist实例

http://blog.163.com/[email protected]/blog/static/74728469201132721428194/ Delphi中Tlist实例 2011-04-27 14:14:28|  分类: Delphi学习 |  标签:list  frmred  tform  frmblue  frmgreen  |举报|字号 订阅 下载LOFTER我的照片书  | unit Unit1; interface uses  Windows, Messages, SysUt

PHP中”单例模式“实例讲解【转】

转自::http://www.cnblogs.com/hongfei/archive/2012/07/07/2580994.html 假设我们需要写一个类用来操作数据库,并同时满足以下要求: ①SqlHelper类只能有一个实例(不能多)②SqlHelper类必须能够自行创建这个实例③必须自行向整个系统提供这个实例,换句话说:多个对象共享一块内存区域,比如,对象A设置了某些属性值,则对象B,C也可以访问这些属性值(结尾的例子很好的说明了这个问题) 1 <?php 2 class SqlHelpe

SQL SERVER 2005中同义词实例

From : http://www.cnblogs.com/jackyrong/archive/2006/11/15/561287.html 在SQL SERVER 2005中,终于出现了同义词了,大大方便了使用.下面举个小例子说明 同义词是用来实现下列用途的数据库对象: 为本地或远程服务器上的另一个数据库对象(称为“基对象”)提供备选名称. 提供一个提取层,该层防止客户端应用程序的基对象的名称或位置被更改. 例如,名为 Server1 的服务器上有 Adventure Works 的 Empl

关于Javascript中通过实例对象修改原型对象属性值的问题

Javascript中的数据值有两大类:基本类型的数据值和引用类型的数据值. 基本类型的数据值有5种:null.undefined.number.boolean和string. 引用类型的数据值往大的说就1种,即Object类型.往细的说有:Object类型.Array类型.Date类型.Regexp类型.Function类型等. 当原型对象的属性值为基本类型的数据值时,通过实例对象修改属性值从而引起原型对象的属性值发生变化的情况不会发生.当原型对象的属性值为引用类型的数据值时,通过实例对象修改

Spring中AOP实例详解

Spring中AOP实例详解 需要增强的服务 假如有以下service,他的功能很简单,打印输入的参数并返回参数. @Service public class SimpleService { public String getName(String name) { System.out.println(get name is: + name); return name; } } 定义切面和切点 @Component @Aspect public class L ogAspect { // 定义切

能否向编译后得到的类中增加实例变量?能否向运行时创建的类中添加实例变量?为什么

不能向编译后得到的类中增加实例变量!能向运行时创建的类中添加实例变量! 因为编译后的类已经注册在runtime中,类结构体中的objc_ivar_list 实例变量的链表和instance_size实例变量的内存大小已经确定,同时runtime 会调用class_setIvarLayout 或 class_setWeakIvarLayout来处理strong weak引用,所以不能向存在的类中添加实例变量. 运行时创建的类是可以添加实例变量,调用 class_addIvar 函数,但是得在调用 

python中的函数存入list中的实例

最近由于接触了python这个强大的东西,在写代码时考虑到代码的扩展性,就想到了将python的函数名存入list中.有点像习惯的c/c++中的函数指针的意思. 下面上代码: 1 # coding=utf-8 2 #!/usr/bin/python 3 #脚本的用法 python nn_daemon.py 4 import json, urllib, urllib2, subprocess, sys, os, logging, time, socket, time, calendar, date

echarts在.Net中使用实例(二) 使用ajax动态加载数据

前一篇文章链接:echarts在.Net中使用实例(一) 简单的Demo 通过上一篇文章可以知道和echarts参考手册可知,series字段就是用来存储我们显示的数据,所以我们只需要用ajax来获取series的值就可以. option 名称 描述 {color}backgroundColor 全图默认背景,(详见backgroundColor),支持rgba,默认为无,透明 {Array} color 数值系列的颜色列表,(详见color),可配数组,eg:['#87cefa', 'rgba

javascript函数中的实例对象、类对象、局部变量(局部函数)

定义 function Person(national,age) { this.age = age; //实例对象,每个示例不同 Person.national = national; //类对象,所用实例公用 var bb = 0; //局部变量,外面不能访问(类似局部函数) } 调用 var p = new Person("中国", 29); document.writeln("age:" + p.age); document.writeln("obj