⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 examplegis.java

📁 一个非常著名的网格模拟器,能够运行网格调度算法!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        // connect all resource entities with r2 router        // For each host, specify which PacketScheduler entity to use.        GridResource resObj = null;        for (i = 0; i < resList.size(); i++)        {            FIFOScheduler resSched = new FIFOScheduler("GridResSched_"+i);            resObj = (GridResource) resList.get(i);            r2.attachHost(resObj, resSched);        }        // then connect r1 to r2        // For each host, specify which PacketScheduler entity to use.        Link link = new SimpleLink("r1_r2_link", baud_rate, propDelay, mtu);        FIFOScheduler r1Sched = new FIFOScheduler("r1_Sched");        FIFOScheduler r2Sched = new FIFOScheduler("r2_Sched");        // attach r2 to r1        r1.attachRouter(r2, link, r1Sched, r2Sched);        // attach r3 to r2        FIFOScheduler r3Sched = new FIFOScheduler("r3_Sched");        link = new SimpleLink("r2_r3_link", baud_rate, propDelay, mtu);        r2.attachRouter(r3, link, r2Sched, r3Sched);        // attach regional GIS entities to r3 router        RegionalGIS gis = null;        for (i = 0; i < gisList.size(); i++)        {            FIFOScheduler gisSched = new FIFOScheduler("gis_Sched" + i);            gis = (RegionalGIS) gisList.get(i);            r3.attachHost(gis, gisSched);        }    }    /**     * Creates one Grid resource. A Grid resource contains one or more     * Machines. Similarly, a Machine contains one or more PEs (Processing     * Elements or CPUs).     */    private static GridResource createGridResource(String name,                int totalPE, int totalMachine, int rating,                double baud_rate, double delay, int MTU)    {        // Here are the steps needed to create a Grid resource:        // 1. We need to create an object of MachineList to store one or more        //    Machines        MachineList mList = new MachineList();        for (int i = 0; i < totalMachine; i++)        {            // 2. A Machine contains one or more PEs or CPUs. Therefore, should            //    create an object of PEList to store these PEs before creating            //    a Machine.            PEList peList = new PEList();            // 3. Create PEs and add these into an object of PEList.            for (int k = 0; k < totalPE; k++)            {                // need to store PE id and MIPS Rating                peList.add( new PE(k, rating) );            }            // 4. Create one Machine with its id and list of PEs or CPUs            mList.add( new Machine(i, peList) );        }        // 5. Create a ResourceCharacteristics object that stores the        //    properties of a Grid resource: architecture, OS, list of        //    Machines, allocation policy: time- or space-shared, time zone        //    and its price (G$/PE time unit).        String arch = "Intel";      // system architecture        String os = "Linux";        // operating system        double time_zone = 10.0;    // time zone this resource located        double cost = 3.0;          // the cost of using this resource        ResourceCharacteristics resConfig = new ResourceCharacteristics(                arch, os, mList, ResourceCharacteristics.SPACE_SHARED,                time_zone, cost);        // 6. Finally, we need to create a GridResource object.        long seed = 11L*13*17*19*23+1;        double peakLoad = 0.0;        // the resource load during peak hour        double offPeakLoad = 0.0;     // the resource load during off-peak hr        double holidayLoad = 0.0;     // the resource load during holiday        // incorporates weekends so the grid resource is on 7 days a week        LinkedList Weekends = new LinkedList();        Weekends.add(new Integer(Calendar.SATURDAY));        Weekends.add(new Integer(Calendar.SUNDAY));        // incorporates holidays. However, no holidays are set in this example        LinkedList Holidays = new LinkedList();        GridResource gridRes = null;        try        {            // creates a GridResource with a link            Link link = new SimpleLink(name + "_link", baud_rate, delay, MTU);            gridRes = new GridResource(name, link, seed, resConfig, peakLoad,                                offPeakLoad, holidayLoad, Weekends, Holidays);        }        catch (Exception e) {            e.printStackTrace();        }        System.out.println("Creating a Grid resource (name: " + name +                " - id: " + gridRes.get_id() + ")");        return gridRes;    }    /**     * Creates one Grid resource that support advance reservation.     * A Grid resource contains one or more     * Machines. Similarly, a Machine contains one or more PEs (Processing     * Elements or CPUs).     */    private static GridResource createARGridResource(String name,                int totalPE, int totalMachine, int rating,                double baud_rate, double delay, int MTU)    {        // Here are the steps needed to create a Grid resource:        // 1. We need to create an object of MachineList to store one or more        //    Machines        MachineList mList = new MachineList();        for (int i = 0; i < totalMachine; i++)        {            // 2. A Machine contains one or more PEs or CPUs. Therefore, should            //    create an object of PEList to store these PEs before creating            //    a Machine.            PEList peList = new PEList();            // 3. Create PEs and add these into an object of PEList.            for (int k = 0; k < totalPE; k++)            {                // need to store PE id and MIPS Rating                peList.add( new PE(k, rating) );            }            // 4. Create one Machine with its id and list of PEs or CPUs            mList.add( new Machine(i, peList) );        }        // 5. Create a ResourceCharacteristics object that stores the        //    properties of a Grid resource: architecture, OS, list of        //    Machines, allocation policy, time zone and its price        String arch = "Sun Ultra";   // system architecture        String os = "Solaris";       // operating system        double cost = 3.0;           // the cost of using this resource (G$/PE)        double timeZone = 11;        // time zone        // NOTE: allocation policy in here is set to        // ResourceCharacteristics.ADVANCE_RESERVATION not SPACE_SHARED nor        // TIME_SHARED.        ResourceCharacteristics resConfig = new ResourceCharacteristics(                arch, os, mList, ResourceCharacteristics.ADVANCE_RESERVATION,                timeZone, cost);        // 6. Finally, we need to create a GridResource object.        long seed = 11L*13*17*19*23+1;        double peakLoad = 0.0;       // the resource load during peak hour        double offPeakLoad = 0.0;    // the resource load during off-peak hr        double holidayLoad = 0.0;    // the resource load during holiday        // incorporates weekends so the grid resource is on 7 days a week        LinkedList Weekends = new LinkedList();        Weekends.add(new Integer(Calendar.SATURDAY));        Weekends.add(new Integer(Calendar.SUNDAY));        // incorporates holidays. However, no holidays are set in this example        LinkedList Holidays = new LinkedList();        ARGridResource gridRes = null;        // creates a resource calendar that handles different loads        ResourceCalendar cal = new ResourceCalendar(                resConfig.getResourceTimeZone(), peakLoad, offPeakLoad,                holidayLoad, Weekends, Holidays, seed);        try        {            // use this AR scheduling algorithm. The name of this entity            // will be name_scheduler, e.g. Resource0_scheduler.            String scheduler = "scheduler";            ARSimpleSpaceShared policy =new ARSimpleSpaceShared(name,scheduler);            // then creates a grid resource entity.            // NOTE: You need to use a grid resource entity that supports            // advanced reservation functionalities. In this case, the entity            // is called ARGridResource.            Link link = new SimpleLink(name + "_link", baud_rate, delay, MTU);            gridRes = new ARGridResource(name, link, resConfig, cal, policy);        }        catch (Exception e) {            e.printStackTrace();        }        System.out.println("Creating an AR Grid resource (name: " + name +                " - id: " + gridRes.get_id() + ")");        return gridRes;    }} // end class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -