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

📄 examplegis.java

📁 一个非常著名的网格模拟器,能够运行网格调度算法!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Author: Anthony Sulistio * Date: March 2005 * Description: *      This example demonstrates how to create multiple regional GIS as part of *      a network topology. In addition, how to query to the assigned regional *      GIS entity from the user's point of view. * * NOTE: GridSim version 3.2 or above is needed to run this example. *       In addition, this example does not care much about sending jobs or *       Gridlets to resources. * * $Id: ExampleGIS.java,v 1.1 2005/03/29 02:13:08 anthony Exp $ */import gridsim.*;import gridsim.index.*;import gridsim.net.*;import java.util.*;/** * A test driver to run multiple regional GIS in a network. * This test driver uses only NetUSerGIS.java file */public class ExampleGIS{    /**     * Creates main() to run this example     */    public static void main(String[] args)    {        System.out.println("Starting GIS-network examples ...");        try        {            //////////////////////////////////////////            // Variables that are important to this example            int num_user = 1;        // number of grid users            int num_GIS = 3;         // number of regional GIS entity created            int totalResource = 8;   // number of grid resources            Random random = new Random();   // a random generator            double baud_rate = 1e8;  // 100 Mbps            double propDelay = 10;   // propagation delay in millisecond            int mtu = 1500;          // max. transmission unit in byte            int i = 0;               // a temp variable for a loop            int gisIndex = 0;        // a variable to select a GIS entity            RegionalGIS gis = null;  // a regional GIS entity            //////////////////////////////////////////            // First step: Initialize the GridSim package. It should be called            // before creating any entities. We can't run this example without            // initializing GridSim first. We will get a run-time exception            // error.            Calendar calendar = Calendar.getInstance();            boolean trace_flag = false;     // true means trace GridSim events            // Initialize the GridSim package            System.out.println("Initializing GridSim package");            GridSim.init(num_user, calendar, trace_flag);            //////////////////////////////////////////            // Second step: Creates one or more regional GIS entities            ArrayList gisList = new ArrayList();  // array            for (i = 0; i < num_GIS; i++)            {                String gisName = "Regional_GIS_" + i;   // regional GIS name                // a network link attached to this regional GIS entity                Link link = new SimpleLink(gisName + "_link", baud_rate,                                           propDelay, mtu);                // create a new regional GIS entity                gis = new RegionalGIS(gisName, link);                System.out.println("Creating a " + gisName + " with id = " +                                   gis.get_id());                // store the regional GIS entity into an array                gisList.add(gis);            }            //////////////////////////////////////////            // Third step: Creates one or more GridResource entities            System.out.println();            ArrayList resList = new ArrayList(totalResource);            int totalPE = 4;        // number of CPUs            int totalMachine = 1;   // number of machines or nodes            int rating = 1500;      // an estimation CPU power            // create a typical resource            int totalAR = random.nextInt(totalResource);            for (i = 0; i < (totalResource - totalAR); i++)            {                GridResource res = createGridResource("Res_" + i,                                        totalPE, totalMachine, rating,                                        baud_rate, propDelay, mtu);                // allocate this resource to a random regional GIS entity                gisIndex = random.nextInt(num_GIS);                gis = (RegionalGIS) gisList.get(gisIndex);                res.setRegionalGIS(gis);    // set the regional GIS entity                resList.add(res);           // put this resource into a list                System.out.println(res.get_name() + " will register to " +                        gis.get_name());                System.out.println();            }            // create a resource that supports advance reservation            for (i = 0; i < totalAR; i++)            {                double time_zone = i;                GridResource res = createARGridResource("AR_Res_" + i,                                        totalPE, totalMachine, rating,                                        baud_rate, propDelay, mtu);                // allocate this resource to a random regional GIS entity                gisIndex = random.nextInt(num_GIS);                gis = (RegionalGIS) gisList.get(gisIndex);                res.setRegionalGIS(gis);    // set the regional GIS entity                resList.add(res);           // put this resource into a list                System.out.println(res.get_name() + " will register to " +                        gis.get_name());                System.out.println();            }            //////////////////////////////////////////            // Fourth step: Creates one or more grid user entities            System.out.println();            ArrayList userList = new ArrayList(num_user);            for (i = 0; i < num_user; i++)            {                NetUserGIS user = new NetUserGIS("User_" + i,                                                 baud_rate, propDelay, mtu);                // allocate this resource to a random regional GIS entity                gisIndex = random.nextInt(num_GIS);                gis = (RegionalGIS) gisList.get(gisIndex);                user.setRegionalGIS(gis);   // set the regional GIS entity                userList.add(user);         // put this user into a list                System.out.println(user.get_name() + " will communicate to " +                        gis.get_name());                System.out.println();            }            //////////////////////////////////////////            // Fifth step: Builds the network topology for all entities.            // In this example, the topology is:            // with Regional GIS the network topology becomes:            // User(s) --- r1 --- r2 --- r3 --- GIS(s)            //                    |            //                    |---- resource(s)            createTopology(gisList, resList, userList);            //////////////////////////////////////////            // Sixth step: Starts the simulation            System.out.println();            GridSim.startGridSimulation();            //////////////////////////////////////////            System.out.println();            System.out.println("Finish GIS-network example ...");        }        catch (Exception e)        {            e.printStackTrace();            System.out.println("Unwanted errors happen");        }    }    /**     * Creates a simple network topology     * In this example, the topology is:     * with Regional GIS the network topology becomes:     * User(s) --- r1 --- r2 --- r3 --- GIS(s)     *                    |     *                    |---- resource(s)     */    private static void createTopology(ArrayList gisList, ArrayList resList,                                       ArrayList userList) throws Exception    {        int i = 0;        double baud_rate = 1e8;  // 100 Mbps        double propDelay = 10;   // propagation delay in millisecond        int mtu = 1500;          // max. transmission unit in byte        // create the routers        Router r1 = new RIPRouter("router1");   // router 1        Router r2 = new RIPRouter("router2");   // router 2        Router r3 = new RIPRouter("router3");   // router 3        // connect all user entities with r1 router        // For each host, specify which PacketScheduler entity to use.        NetUserGIS obj = null;        for (i = 0; i < userList.size(); i++)        {            FIFOScheduler userSched = new FIFOScheduler("NetUserSched_"+i);            obj = (NetUserGIS) userList.get(i);            r1.attachHost(obj, userSched);        }

⌨️ 快捷键说明

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