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");
        }
    }