From: <mar...@us...> - 2008-05-27 07:55:38
|
Revision: 175 http://gridsim.svn.sourceforge.net/gridsim/?rev=175&view=rev Author: marcos_dias Date: 2008-05-27 00:55:44 -0700 (Tue, 27 May 2008) Log Message: ----------- This update includes and example on how to use the continuous double auction. It also allows the user to change the id of an auction. Modified Paths: -------------- trunk/source/gridsim/auction/Auction.java Added Paths: ----------- trunk/examples/Auction/AuctionEx03/ trunk/examples/Auction/AuctionEx03/AuctionResource.java trunk/examples/Auction/AuctionEx03/Broker.java trunk/examples/Auction/AuctionEx03/ExampleAuction.java trunk/examples/Auction/AuctionEx03/NetUser.java trunk/examples/Auction/AuctionEx03/README.txt trunk/examples/Auction/AuctionEx03/ResponderImpl.java trunk/examples/Auction/AuctionEx03/output.txt Added: trunk/examples/Auction/AuctionEx03/AuctionResource.java =================================================================== --- trunk/examples/Auction/AuctionEx03/AuctionResource.java (rev 0) +++ trunk/examples/Auction/AuctionEx03/AuctionResource.java 2008-05-27 07:55:44 UTC (rev 175) @@ -0,0 +1,182 @@ +/* + * Author: Marcos Dias de Assuncao + * Date: May 2008 + * Description: A simple program to demonstrate of how to use GridSim + * auction extension package. + * This example shows how to create user, resource, auctioneer + * and auction entities connected via a network topology, + * using link and router. + * + */ + +import eduni.simjava.Sim_event; +import eduni.simjava.distributions.ContinuousGenerator; +import eduni.simjava.distributions.Sim_uniform_obj; +import gridsim.AllocPolicy; +import gridsim.GridResource; +import gridsim.GridSimTags; +import gridsim.ResourceCalendar; +import gridsim.ResourceCharacteristics; +import gridsim.auction.AuctionObserver; +import gridsim.auction.AuctionTags; +import gridsim.auction.MessageAsk; +import gridsim.auction.Responder; +import gridsim.net.Link; + +import java.util.Calendar; + +/** + * This class implements a resource that has an observer for an auction + * + * @author Marcos Dias de Assuncao + */ +public class AuctionResource extends GridResource { + private AuctionObserver observer; + private ContinuousGenerator priceGenerator; + private int secondsBetweenAsks = 60; + private int auctioneerId = -1; + + // a tag ID to be used to schedule an event to this entity to create an ask + private static final int CREATE_ASK_TAG = 7001; + + /** + * Allocates a new GridResource object. + * + * @param name the name to be associated with this entity (as + * required by Sim_entity class from simjava package) + * @param baud_rate network communication or bandwidth speed + * @param resource an object of ResourceCharacteristics + * @param calendar an object of ResourceCalendar + * @param policy a scheduling policy for this Grid resource. If no + * scheduling policy is defined, the default one is + * <tt>SpaceShared</tt> + * @throws Exception This happens when one of the following scenarios occur: + * <ul> + * <li> creating this entity before initializing GridSim package + * <li> this entity name is <tt>null</tt> or empty + * <li> this entity has <tt>zero</tt> number of PEs (Processing + * Elements). <br> + * No PEs mean the Gridlets can't be processed. + * A GridResource must contain one or more Machines. + * A Machine must contain one or more PEs. + * </ul> + * @see gridsim.GridResource#GridResource(String, double, ResourceCharacteristics, ResourceCalendar, AllocPolicy) + */ + public AuctionResource(String name, double baud_rate, + ResourceCharacteristics resource, + ResourceCalendar calendar, + AllocPolicy policy) throws Exception{ + + super(name,baud_rate,resource,calendar,policy); + + Responder responder = new ResponderImpl(resource,calendar,policy); + observer = new AuctionObserver(this.get_id(),"Observer_1",this.output,responder); + } + + /** + * Allocates a new GridResource object. When making a different type of + * GridResource object, use this constructor and then overrides + * {@link #processOtherEvent(Sim_event)}. + * + * @param name the name to be associated with this entity (as + * required by Sim_entity class from simjava package) + * @param link the link that will be used to connect this + * GridResource to another Entity or Router. + * @param resource an object of ResourceCharacteristics + * @param calendar an object of ResourceCalendar + * @param policy a scheduling policy for this Grid resource. If no + * scheduling policy is defined, the default one is + * <tt>SpaceShared</tt> + * @throws Exception This happens when one of the following scenarios occur: + * <ul> + * <li> creating this entity before initializing GridSim package + * <li> this entity name is <tt>null</tt> or empty + * <li> this entity has <tt>zero</tt> number of PEs (Processing + * Elements). <br> + * No PEs mean the Gridlets can't be processed. + * A GridResource must contain one or more Machines. + * A Machine must contain one or more PEs. + * </ul> + * @see gridsim.GridSim#init(int, Calendar, boolean, String[], String[], + * String) + * @see gridsim.AllocPolicy + * @pre name != null + * @pre link != null + * @pre resource != null + * @pre calendar != null + * @pre policy != null + * @post $none + */ + public AuctionResource(String name, Link link, + ResourceCharacteristics resource, + ResourceCalendar calendar, + AllocPolicy policy) throws Exception{ + + super(name,link,resource,calendar,policy); + + Responder responder = new ResponderImpl(resource,calendar,policy); + observer = new AuctionObserver(this.get_id(),"Observer_1",this.output,responder); + } + + /** + * Returns the auction observer for this resource + * @param observer + * @return the observer for this resource + */ + public boolean setAuctionObserver(AuctionObserver observer){ + if(observer == null) + return false; + + this.observer = observer; + return true; + } + + /** + * Defines the behaviour of this entity + */ + public void body() { + // creates a uniform distribution to create prices between $1 and $2 + long seed = 11L*13*17*19*23+1; + priceGenerator = new Sim_uniform_obj("priceGen", 1, 2, seed); + super.sim_schedule(super.get_id(), secondsBetweenAsks, CREATE_ASK_TAG); + super.body(); + } + + /** + * Since we are implementing other resource, this method has to be + * implemented in order to make resource able to deal with other kind + * of events. + * This method is called by {@link #body()} for incoming unknown tags. + * + * @param ev a Sim_event object + * @pre ev != null + * @post $none + */ + protected void processOtherEvent(Sim_event ev){ + if(ev.get_tag() == CREATE_ASK_TAG) { + createAsk(); + super.sim_schedule(super.get_id(), secondsBetweenAsks, CREATE_ASK_TAG); + } + else { + observer.processEvent(ev); + } + } + + /** + * Sets the ID of the auctioneer to whom this resource will send asks + * @param id the auctioneer's ID + */ + public void setAuctioneerID(int id) { + auctioneerId = id; + } + + /* + * Creates an ask and sends it to the auctioneer + */ + private void createAsk() { + float price = (float)priceGenerator.sample(); + MessageAsk ask = new MessageAsk(0, AuctionTags.CONTINUOUS_DOUBLE_AUCTION, price); + ask.setSourceID(super.get_id()); + super.send(auctioneerId, GridSimTags.SCHEDULE_NOW, AuctionTags.AUCTION_ASK, ask); + } +} \ No newline at end of file Added: trunk/examples/Auction/AuctionEx03/Broker.java =================================================================== --- trunk/examples/Auction/AuctionEx03/Broker.java (rev 0) +++ trunk/examples/Auction/AuctionEx03/Broker.java 2008-05-27 07:55:44 UTC (rev 175) @@ -0,0 +1,122 @@ +/* + * Author: Marcos Dias de Assuncao + * Date: May 2008 + * Description: A simple program to demonstrate of how to use GridSim + * auction extension package. + * This example shows how to create user, resource, auctioneer + * and auction entities connected via a network topology, + * using link and router. + */ + +import eduni.simjava.Sim_event; +import eduni.simjava.Sim_port; +import gridsim.GridSimTags; +import gridsim.Gridlet; +import gridsim.auction.Auction; +import gridsim.auction.Auctioneer; +import gridsim.auction.ContinuousDoubleAuction; +import gridsim.auction.MessageAsk; +import gridsim.auction.MessageBid; +import gridsim.net.SimpleLink; + +/** + * This class implements a broker for the user. The broker bids containing jobs + * from the users, behaves as an auctioneer, creates a double auction, and submits + * jobs after a match of ask and bid is found. + * + * @author Marcos Dias de Assuncao + */ +public class Broker extends Auctioneer { + private ContinuousDoubleAuction auction = null; + private int numUsers; + private int finishedUsers = 0; + protected static final int FINISHED_EXPERIMENTS = 7002; + + /** + * Constructor + * @param name a name for the broker + * @param baud_rate the baud rate of the link to which the broker is attached + * @param delay the delay of the link + * @param MTU the maximum transfer unit of the link + * @throws Exception + * @see gridsim.auction.Auctioneer + * @see gridsim.GridSim + */ + public Broker(String name, double baud_rate, double delay, + int MTU, int numUsers) throws Exception{ + super( name, new SimpleLink(name+"_link",baud_rate,delay, MTU) ); + this.numUsers = numUsers; + } + + /** + * Returns the output port of the broker + * @return a port which corresponds to the output port of the entity + */ + public Sim_port getOutputPort(){ + return this.output; + } + + /** + * This method is called when an auction is finished + * @see gridsim.auction.Auctioneer#onAuctionClose(gridsim.auction.Auction) + */ + public synchronized void onAuctionClose(Auction auction){ + return; + } + + /** + * This method is called when a match for a double auction is found. + * OBS: We don't use double auctions in this example + * @see gridsim.auction.Auctioneer#onResponseToAsk(gridsim.auction.MessageAsk, gridsim.auction.MessageBid, double) + */ + public synchronized void onResponseToAsk(MessageAsk ask, MessageBid bid, double price){ + Gridlet job = (Gridlet)bid.getAttribute("job"); + + System.out.println("\nA MATCH of an ASK with a BID has been performed:" + + "\nBID details:" + + "\nSender's ID: " + bid.getSourceID() + + "\nPrice offered for executing the job: " + bid.getPrice() + + "\nASK details:" + + "\nSender's ID: " + ask.getSourceID() + + "\nPrice asked for executing the job: " + ask.getPrice() + + "\nPrice given by the auctioneer: " + price); + + gridletSubmit(job, ask.getSourceID()); + } + + public void body() { + try { + // waits 10 second to start the auction + super.gridSimHold(10.0); + + auction = + new ContinuousDoubleAuction(super.get_name() + "_CDA", super.get_id(), + Double.MAX_VALUE, this.output); + + System.out.println("Creating Auction " + auction.getAuctionID()); + + // add the auction + super.addAuction(auction); + + // start the auction + super.startAuction(auction.getAuctionID()); + + } catch (Exception e) { + e.printStackTrace(); + } + + super.body(); + } + + public void processOtherEvent(Sim_event ev) { + + if(ev.get_tag() == Broker.FINISHED_EXPERIMENTS) { + finishedUsers++; + } + + if(finishedUsers >= numUsers) { + super.send(auction.get_id(), GridSimTags.SCHEDULE_NOW, GridSimTags.END_OF_SIMULATION); + super.send(super.get_id(), 0, GridSimTags.END_OF_SIMULATION); + } + } +} Added: trunk/examples/Auction/AuctionEx03/ExampleAuction.java =================================================================== --- trunk/examples/Auction/AuctionEx03/ExampleAuction.java (rev 0) +++ trunk/examples/Auction/AuctionEx03/ExampleAuction.java 2008-05-27 07:55:44 UTC (rev 175) @@ -0,0 +1,304 @@ +/* + * Author: Marcos Dias de Assuncao + * Date: May 2008 + * Description: A simple program to demonstrate of how to use GridSim + * auction extension package. + * This example shows how to create user, resource, auctioneer + * and auction entities connected via a network topology, + * using link and router. + * + */ + +import eduni.simjava.distributions.Sim_uniform_obj; +import gridsim.GridResource; +import gridsim.GridSim; +import gridsim.Machine; +import gridsim.MachineList; +import gridsim.PE; +import gridsim.PEList; +import gridsim.ResourceCalendar; +import gridsim.ResourceCharacteristics; +import gridsim.net.FIFOScheduler; +import gridsim.net.Link; +import gridsim.net.RIPRouter; +import gridsim.net.Router; +import gridsim.net.SimpleLink; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.LinkedList; + +/** + * This class creates resources, users and routers and links them + * in a network topology. This examples uses a continuous double auction. + * + * @author Marcos Dias de Assuncao + */ +public class ExampleAuction { + + /** + * Creates one Grid resource. A Grid resource contains one or more + * Machines. Similarly, a Machine contains one or more PEs (Processing + * Elements or CPUs). + * <p> + * In this simple example, we are simulating one Grid resource with three + * Machines that contains one or more PEs. + * @param name a Grid Resource name + * @param baud_rate the bandwidth of this entity + * @param delay the propagation delay + * @param MTU Maximum Transmission Unit + * @param cost the cost of using this resource + * @param mips Capability of a CPU in MIPS + * @return a GridResource object + */ + private static GridResource createGridResource(String name, + double baud_rate, double delay, int MTU, + double cost, int mips, int auctioneerId) + { + System.out.println(); + System.out.println("Starting to create one Grid resource with " + + "3 Machines"); + + // 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(); + //System.out.println("Creates a Machine list"); + + + // 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 peList1 = new PEList(); + //System.out.println("Creates a PE list for the 1st Machine"); + + + // 3. Create PEs and add these into an object of PEList. + // In this example, we are using a resource from + // hpc420.hpcc.jp, AIST, Tokyo, Japan + // Note: these data are taken the from GridSim paper, page 25. + // In this example, all PEs has the same MIPS (Millions + // Instruction Per Second) Rating for a Machine. + peList1.add( new PE(0, mips) ); // need to store PE id and MIPS Rating + peList1.add( new PE(1, mips) ); + peList1.add( new PE(2, mips) ); + peList1.add( new PE(3, mips) ); + //System.out.println("Creates 4 PEs with same MIPS Rating and put them"+ + // " into the PE list"); + + + // 4. Create one Machine with its id and list of PEs or CPUs + mList.add( new Machine(0, peList1) ); // First Machine + //System.out.println("Creates the 1st Machine that has 4 PEs and " + + // "stores it into the Machine list"); + //System.out.println(); + + // 5. Repeat the process from 2 if we want to create more Machines + // In this example, the AIST in Japan has 3 Machines with same + // MIPS Rating but different PEs. + // NOTE: if you only want to create one Machine for one Grid resource, + // then you could skip this step. + PEList peList2 = new PEList(); + //System.out.println("Creates a PE list for the 2nd Machine"); + + peList2.add( new PE(0, mips) ); + peList2.add( new PE(1, mips) ); + peList2.add( new PE(2, mips) ); + peList2.add( new PE(3, mips) ); + //System.out.println("Creates 4 PEs with same MIPS Rating and put them"+ + // " into the PE list"); + + mList.add( new Machine(1, peList2) ); // Second Machine + //System.out.println("Creates the 2nd Machine that has 4 PEs and " + + // "stores it into the Machine list"); + //System.out.println(); + + PEList peList3 = new PEList(); + //System.out.println("Creates a PE list for the 3rd Machine"); + + peList3.add( new PE(0, mips) ); + peList3.add( new PE(1, mips) ); + //System.out.println("Creates 2 PEs with same MIPS Rating and put them"+ + // " into the PE list"); + + mList.add( new Machine(2, peList3) ); // Third Machine + //System.out.println("Creates the 3rd Machine that has 2 PEs and " + + // "stores it into the Machine list"); + //System.out.println(); + + // 6. 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 = "Sun Ultra"; // system architecture + String os = "Solaris"; // operating system + double time_zone = 9.0; // time zone this resource located + + ResourceCharacteristics resConfig = new ResourceCharacteristics( + arch, os, mList, ResourceCharacteristics.TIME_SHARED, + time_zone, cost); + + //System.out.println("Creates the properties of a Grid resource and " + + // "stores the Machine list"); + + // 7. 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(); + + ResourceCalendar calendar = new ResourceCalendar(time_zone, peakLoad, + offPeakLoad, holidayLoad, weekends, holidays, seed); + + AuctionResource gridRes = null; + try + { + // creates a GridResource with a link + gridRes = new AuctionResource(name, + new SimpleLink(name + "_link", baud_rate, delay, MTU), + resConfig,calendar, null); + + gridRes.setAuctioneerID(auctioneerId); + } + catch (Exception e) { + e.printStackTrace(); + } + + System.out.println("Finally, creates one Grid resource (name: " + name + + " - id: " + gridRes.get_id() + ")"); + + System.out.println(); + return gridRes; + } + + /** + * + * @param args + */ + public static void main(String[] args) { + try{ + Calendar calendar = Calendar.getInstance(); + boolean trace_flag = true; // mean trace GridSim events + int num_user = 3; + int num_resource = 2; + int num_gridlet = 3; + + // First step: Initialize the GridSim package. It should be called + // before creating any entities. We can't run GridResource + // entity without initializing GridSim first. We will get run-time + // exception error. + + // Initialize the GridSim package + System.out.println("Initializing GridSim package"); + GridSim.init(num_user, calendar, trace_flag); + + double baud_rate = 1000; // bits/sec + double propDelay = 10; // propagation delay in millisecond + int mtu = 1500; // max. transmission unit in byte + + long seed = 11L*13*17*19*23+1; + + Sim_uniform_obj genCost = new Sim_uniform_obj("cost",1,2, seed); + Sim_uniform_obj genMIPS = new Sim_uniform_obj("mips",300,400, seed); + + + Broker broker = new Broker("Broker", baud_rate, propDelay, mtu, num_user); + + // more resources can be created by + // setting num_resource to an appropriate value + ArrayList resList = new ArrayList(num_resource); + for (int i = 0; i < num_resource; i++) { + GridResource res = createGridResource("Resource_"+i, baud_rate, + propDelay, mtu, genCost.sample(), + ((int)genMIPS.sample()), broker.get_id()); + // add a resource into a list + resList.add(res); + } + + // create users + ArrayList userList = new ArrayList(num_user); + for (int i = 0; i < num_user; i++) + { + NetUser user = new NetUser("User_" + i, num_gridlet, + baud_rate, propDelay, mtu, broker); + + // add a user into a list + userList.add(user); + } + + ////////////////////////////////////////// + // Fourth step: Builds the network topology among entities. + + // In this example, the topology is: + // user(s) --1Mb/s-- r1 --10Mb/s-- r2 --1Mb/s-- GridResource(s) + + // create the routers. + // If trace_flag is set to "true", then this experiment will create + // the following files (apart from sim_trace and sim_report): + // - router1_report.csv + // - router2_report.csv + Router r1 = new RIPRouter("router1", trace_flag); // router 1 + Router r2 = new RIPRouter("router2", trace_flag); // router 2 + + FIFOScheduler brokerSched = new FIFOScheduler("NetBrokerSched"); + r1.attachHost(broker, brokerSched); + + // connect all user entities with r1 with 1Mb/s connection + // For each host, specify which PacketScheduler entity to use. + NetUser user = null; + for (int i = 0; i < userList.size(); i++) + { + // A First In First Out Scheduler is being used here. + // SCFQScheduler can be used for more fairness + FIFOScheduler userSched = new FIFOScheduler("NetUserSched_"+i); + user = (NetUser) userList.get(i); + r1.attachHost(user, userSched); + } + + // connect all resource entities with r2 with 1Mb/s connection + + // For each host, specify which PacketScheduler entity to use. + GridResource resObj = null; + for (int 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 with 10Mb/s connection + // For each host, specify which PacketScheduler entity to use. + baud_rate = 10000; + 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); + + ////////////////////////////////////////// + // Starts the simulation + GridSim.startGridSimulation(); + + ////////////////////////////////////////// + // Final step: Prints the Gridlets when simulation is over + +// // also prints the routing table +// r1.printRoutingTable(); +// r2.printRoutingTable(); + } + catch(Exception ex){ + System.out.println(" Error executing simulation. Message: " + ex.getMessage()); + ex.printStackTrace(); + } + } + +} Added: trunk/examples/Auction/AuctionEx03/NetUser.java =================================================================== --- trunk/examples/Auction/AuctionEx03/NetUser.java (rev 0) +++ trunk/examples/Auction/AuctionEx03/NetUser.java 2008-05-27 07:55:44 UTC (rev 175) @@ -0,0 +1,164 @@ +/* + * Author: Marcos Dias de Assuncao + * Date: May 2008 + * Description: A simple program to demonstrate of how to use GridSim + * auction extension package. + * This example shows how to create user, resource, auctioneer + * and auction entities connected via a network topology, + * using link and router. + * + * This class was adapted from examples on network + * package developed by: Anthony Sulistio + * + */ + + +import eduni.simjava.Sim_event; +import eduni.simjava.Sim_system; +import eduni.simjava.distributions.ContinuousGenerator; +import eduni.simjava.distributions.Sim_uniform_obj; +import gridsim.GridSim; +import gridsim.GridSimTags; +import gridsim.Gridlet; +import gridsim.GridletList; +import gridsim.auction.AuctionTags; +import gridsim.auction.MessageBid; +import gridsim.net.SimpleLink; + +import java.util.Iterator; + + +/** + * This class basically creates Gridlets and submits them to a + * particular Broker in a network topology. + */ +class NetUser extends GridSim +{ + private int myId_; // my entity ID + private GridletList jobs; // list of jobs to be executed + private GridletList receiveJobs; // list of received Gridlets + private Broker broker; + private ContinuousGenerator priceGenerator; + private int secondsBetweenJobs = 60; + + /** + * Creates a new NetUser object + * @param name this entity name + * @param totalGridlet total number of Gridlets to be created + * @param baud_rate the baud rate of the link to which this user is attached + * @param delay the delay of the link + * @param MTU the maximum transfer unit of the link + * @param broker the broker associated with this user + * @throws Exception This happens when name is null or haven't + * initialized GridSim. + */ + NetUser(String name, int totalGridlet, double baud_rate, double delay, + int MTU, Broker broker) throws Exception { + super( name, new SimpleLink(name+"_link",baud_rate,delay, MTU) ); + + this.receiveJobs = new GridletList(); + this.jobs = new GridletList(); + this.broker = broker; + + // Gets an ID for this entity + this.myId_ = super.getEntityId(name); + + // Creates a list of Gridlets or Tasks for this grid user + this.createGridlet(myId_, totalGridlet); + long seed = 11L*13*17*19*23+1; + priceGenerator = new Sim_uniform_obj("price",1, 2, seed); + } + + /** + * The core method that handles communications among GridSim entities. + */ + public void body() { + // wait for a little while for about 10 seconds. + // This to give a time for GridResource entities to register their + // services to GIS (GridInformationService) entity. + super.gridSimHold(10.0); + double previous = 0; + + Iterator it = jobs.iterator(); + while(it.hasNext()) { + previous += secondsBetweenJobs; + + MessageBid bid = new MessageBid(0, AuctionTags.CONTINUOUS_DOUBLE_AUCTION, + 1, super.get_id()); + + bid.setPrice(priceGenerator.sample()); + bid.setAttribute("job", it.next()); + + super.send(broker.get_id(), + secondsBetweenJobs, + AuctionTags.AUCTION_PROPOSE, bid); + } + + // hold for few period - few seconds since the Gridlets length are + // quite huge for a small bandwidth + super.gridSimHold(5); + + Object data; + Gridlet gl; + + Sim_event ev = new Sim_event(); + while ( Sim_system.running() ) + { + super.sim_get_next(ev); // get the next available event + data = ev.get_data(); // get the event's data + + // get the Gridlet data + if (data != null && data instanceof Gridlet) + { + gl = (Gridlet) data; + receiveJobs.add(gl); + } + + // if all the Gridlets have been collected + if (receiveJobs.size() == jobs.size()) { + break; + } + } + + super.send(broker.get_id(), GridSimTags.SCHEDULE_NOW, + Broker.FINISHED_EXPERIMENTS); + + //////////////////////////////////////////////////////// + // shut down I/O ports + shutdownUserEntity(); + terminateIOEntities(); + + +// super.send(broker.get_id(), GridSimTags.SCHEDULE_NOW, +// GridSimTags.END_OF_SIMULATION); + } + + /** + * Gets a list of received Gridlets + * @return a list of received/completed Gridlets + */ + public GridletList getGridletList() { + return receiveJobs; + } + + /** + * This method will show you how to create Gridlets + * @param userID owner ID of a Gridlet + * @param numGridlet number of Gridlet to be created + */ + private void createGridlet(int userID, int numGridlet) + { + int data = 500; // 500KB of data + for (int i = 0; i < numGridlet; i++) + { + // Creates a Gridlet + Gridlet gl = new Gridlet(i, data, data, data); + gl.setUserID(userID); + + // add this gridlet into a list + this.jobs.add(gl); + } + } + +} // end class + Added: trunk/examples/Auction/AuctionEx03/README.txt =================================================================== --- trunk/examples/Auction/AuctionEx03/README.txt (rev 0) +++ trunk/examples/Auction/AuctionEx03/README.txt 2008-05-27 07:55:44 UTC (rev 175) @@ -0,0 +1,49 @@ + +/** + * Author: Anthony Sulistio + * Date: March 2006 + */ + + +Welcome to the Example of how to use GridSim auction extension. +To compile the example source code: + In Unix/Linux: javac -classpath $GRIDSIM/jars/gridsim.jar:. ExampleAuction.java + In Windows: javac -classpath %GRIDSIM%\jars\gridsim.jar;. ExampleAuction.java + +where $GRIDSIM or %GRIDSIM% is the location of the gridsimtoolkit package. + + +To run the class file: + In Unix/Linux: java -classpath $GRIDSIM/jars/gridsim.jar:. ExampleAuction > file.txt + In Windows: java -classpath %GRIDSIM%\jars\gridsim.jar;. ExampleAuction > file.txt + + +The above command means run the program and output the results into a file +named "file.txt" rather than into screen or standard output. +To prevent from overwriting an existing file, I renamed "file.txt" into +"output.txt" +NOTE: When you open "output.txt" file, it tells you that grid user entities + sending Gridlets to a selected grid resource. + + +When running the example file, it will produce the following files: + + sim_trace -> created by the SimJava2 package (lower-level) to trace every + events (performed by SimJava and GridSim) during the simulation. + We don't need to worry about this file. Not to important for our + example. + + sim_report -> created by the SimJava2 package (lower-level) of GridSim. + This is a simulation report that contains general information about + running this experiment. We don't need to worry about this file. + Not to important for our example. + + *.csv -> created by NetUser.java and gridsim.net.RIPRouter.java + to record every incoming activities. + The format of this file is: + simulation_time, ... + + where ... means other descriptive information. + +NOTE: sim_trace, sim_report and all *.csv files will be overwritten if running + a new experiment. Added: trunk/examples/Auction/AuctionEx03/ResponderImpl.java =================================================================== --- trunk/examples/Auction/AuctionEx03/ResponderImpl.java (rev 0) +++ trunk/examples/Auction/AuctionEx03/ResponderImpl.java 2008-05-27 07:55:44 UTC (rev 175) @@ -0,0 +1,87 @@ +/* + * Author: Marcos Dias de Assuncao + * Date: May 2008 + * Description: A simple program to demonstrate of how to use GridSim + * auction extension package. + * This example shows how to create user, resource, auctioneer + * and auction entities connected via a network topology, + * using link and router. + * + */ + +import gridsim.AllocPolicy; +import gridsim.ResourceCalendar; +import gridsim.ResourceCharacteristics; +import gridsim.auction.Message; +import gridsim.auction.MessageCallForBids; +import gridsim.auction.MessageInformOutcome; +import gridsim.auction.MessageInformStart; +import gridsim.auction.MessageRejectBid; +import gridsim.auction.Responder; + +/** + * This class implements a responder for an auction. + * + * @author Marcos Dias de Assuncao + * + */ +public class ResponderImpl implements Responder { + // this distribution is used to generate an + // internal price for the resource + private ResourceCharacteristics resource; + + /** + * Constructor (parameters are used just to ilustrate that the responder could + * take into account the usage of the resource or a give policy to formulate a bid + * @param resource + * @param calendar + * @param policy + * @throws Exception + */ + public ResponderImpl(ResourceCharacteristics resource, + ResourceCalendar calendar, + AllocPolicy policy) throws Exception{ + this.resource = resource; + } + + /** + * This method is invoked when a call for bids is received + * @param msg the call for bids received + * @return the reply message to the call for bids + * @see gridsim.auction.Responder#onReceiveCfb(MessageCallForBids) + */ + public Message onReceiveCfb(MessageCallForBids msg) { + return null; + } + + /** + * This method is invoked when an inform outcome message is received + * @param msg the inform outcome received + * @return the reply message to the inform outcome + * @see gridsim.auction.Responder#onReceiveInformOutcome(gridsim.auction.MessageInformOutcome) + */ + public Message onReceiveInformOutcome(MessageInformOutcome msg){ + return null; + } + + /** + * This method is invoked when a reject for proposal is received + * @param msg the reject proposal received + * @return the reply message to the reject proposal + * @see gridsim.auction.Responder#onReceiveRejectProposal(MessageRejectBid) + */ + public Message onReceiveRejectProposal(MessageRejectBid msg){ + return null; + } + + /** + * This method is invoked when an auction starts and an + * inform start message is received + * @param inform start received + * @return the reply message to the inform start + * @see gridsim.auction.Responder#onReceiveStartAuction(MessageInformStart) + */ + public Message onReceiveStartAuction(MessageInformStart inform){ + return null; + } +} \ No newline at end of file Added: trunk/examples/Auction/AuctionEx03/output.txt =================================================================== --- trunk/examples/Auction/AuctionEx03/output.txt (rev 0) +++ trunk/examples/Auction/AuctionEx03/output.txt 2008-05-27 07:55:44 UTC (rev 175) @@ -0,0 +1,106 @@ +Initializing GridSim package +Initialising... + +Starting to create one Grid resource with 3 Machines +Finally, creates one Grid resource (name: Resource_0 - id: 6) + + +Starting to create one Grid resource with 3 Machines +Finally, creates one Grid resource (name: Resource_1 - id: 12) + +User_0 creating a FPSA to acquire resource to execute job 0 from user 22 +User_0 creating an EA to acquire resource to execute job 1 from user 22 +User_0 creating a DA to acquire resource to execute job 2 from user 22 +User_1 creating a FPSA to acquire resource to execute job 0 from user 33 +User_1 creating an EA to acquire resource to execute job 1 from user 33 +User_1 creating a DA to acquire resource to execute job 2 from user 33 +User_2 creating a FPSA to acquire resource to execute job 0 from user 44 +User_2 creating an EA to acquire resource to execute job 1 from user 44 +User_2 creating a DA to acquire resource to execute job 2 from user 44 +Starting GridSim version 4.0 +Entities started. +Broker_0 starting the auction 0 to acquire resource to execute job 0 from user 22 +Broker_1 starting the auction 3 to acquire resource to execute job 0 from user 33 +Broker_2 starting the auction 6 to acquire resource to execute job 0 from user 44 +Broker_1 starting the auction 4 to acquire resource to execute job 1 from user 33 +Broker_2 starting the auction 7 to acquire resource to execute job 1 from user 44 +Broker_0 starting the auction 1 to acquire resource to execute job 1 from user 22 +Broker_2 starting the auction 8 to acquire resource to execute job 2 from user 44 +Broker_1 starting the auction 5 to acquire resource to execute job 2 from user 33 +Broker_0 starting the auction 2 to acquire resource to execute job 2 from user 22 +Resource_1 bidding for auction 2 round 2 and price 22.5 +Resource_0 bidding for auction 2 round 2 and price 22.5 +Resource_1 bidding for auction 5 round 2 and price 22.5 +Resource_0 bidding for auction 5 round 2 and price 22.5 +Resource_1 bidding for auction 8 round 2 and price 22.5 +Results of the auction +Winner ID: 12 +Price paid for executing the job 2: 22.5 +Submitted by user 22 +Resource_0 bidding for auction 8 round 2 and price 22.5 +Results of the auction +Winner ID: 12 +Price paid for executing the job 2: 22.5 +Submitted by user 33 +Results of the auction +Winner ID: 12 +Price paid for executing the job 2: 22.5 +Submitted by user 44 +Resource_1 bidding for auction 0 round 1 and price 7.62717866897583 +Resource_0 bidding for auction 0 round 1 and price 7.62717866897583 +Resource_1 bidding for auction 3 round 1 and price 7.017467021942139 +Resource_0 bidding for auction 3 round 1 and price 7.017467021942139 +Resource_1 bidding for auction 6 round 1 and price 2.2087604999542236 +Resource_0 bidding for auction 6 round 1 and price 2.2087604999542236 +Results of the auction +Winner ID: 12 +Price paid for executing the job 0: 7.62717866897583 +Submitted by user 22 +Results of the auction +Winner ID: 12 +Price paid for executing the job 0: 7.017467021942139 +Submitted by user 33 +Results of the auction +Winner ID: 12 +Price paid for executing the job 0: 2.2087604999542236 +Submitted by user 44 +Resource_1 bidding for auction 1 round 1 and price 90.0 +Resource_0 bidding for auction 1 round 1 and price 90.0 +Resource_1 bidding for auction 4 round 1 and price 90.0 +Resource_1 bidding for auction 7 round 1 and price 90.0 +Resource_0 bidding for auction 7 round 1 and price 90.0 +Resource_0 bidding for auction 4 round 1 and price 90.0 +Resource_1 bidding for auction 4 round 2 and price 67.5 +Resource_0 bidding for auction 1 round 2 and price 67.5 +Resource_1 bidding for auction 7 round 2 and price 67.5 +Resource_0 bidding for auction 4 round 2 and price 67.5 +Resource_1 bidding for auction 1 round 2 and price 67.5 +Resource_0 bidding for auction 7 round 2 and price 67.5 +Resource_1 bidding for auction 1 round 3 and price 45.0 +Resource_1 bidding for auction 4 round 3 and price 45.0 +Resource_0 bidding for auction 7 round 3 and price 45.0 +Resource_0 bidding for auction 1 round 3 and price 45.0 +Resource_1 bidding for auction 7 round 3 and price 45.0 +Resource_0 bidding for auction 4 round 3 and price 45.0 +Resource_1 bidding for auction 1 round 4 and price 22.5 +Resource_0 bidding for auction 1 round 4 and price 22.5 +Resource_1 bidding for auction 7 round 4 and price 22.5 +Resource_0 bidding for auction 7 round 4 and price 22.5 +Resource_1 bidding for auction 4 round 4 and price 22.5 +Resource_0 bidding for auction 4 round 4 and price 22.5 +Results of the auction +Winner ID: 12 +Price paid for executing the job 1: 22.5 +Submitted by user 22 +Results of the auction +Winner ID: 12 +Price paid for executing the job 1: 22.5 +Submitted by user 33 +Results of the auction +Winner ID: 12 +Price paid for executing the job 1: 22.5 +Submitted by user 44 +GridInformationService: Notify all GridSim entities for shutting down. +Sim_system: No more future events +Gathering simulation data. +Simulation completed. Modified: trunk/source/gridsim/auction/Auction.java =================================================================== --- trunk/source/gridsim/auction/Auction.java 2008-05-19 04:23:04 UTC (rev 174) +++ trunk/source/gridsim/auction/Auction.java 2008-05-27 07:55:44 UTC (rev 175) @@ -151,6 +151,19 @@ } /** + * Sets the auction's ID manually + * @param id the id to be used by the auction + * @return <tt>true</tt> if the ID has been set; <tt>false</tt> otherwise. + */ + public boolean setAuctionID(int id) { + if(id < 0) + return false; + + auctionID = id; + return true; + } + + /** * Returns the ID of this auction * @return auction ID */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |