From: <mar...@us...> - 2007-09-14 07:33:31
|
Revision: 58 http://gridsim.svn.sourceforge.net/gridsim/?rev=58&view=rev Author: marcos_dias Date: 2007-09-14 00:33:33 -0700 (Fri, 14 Sep 2007) Log Message: ----------- Alpha version of GridSim Turbo Added Paths: ----------- branches/gridsim4.0-branch3/.classpath branches/gridsim4.0-branch3/.project branches/gridsim4.0-branch3/examples/ branches/gridsim4.0-branch3/examples/examples/ branches/gridsim4.0-branch3/examples/examples/workload/ branches/gridsim4.0-branch3/examples/examples/workload/parallel/ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExample01.java branches/gridsim4.0-branch3/source/ branches/gridsim4.0-branch3/source/eduni/ branches/gridsim4.0-branch3/source/eduni/simdiag/ branches/gridsim4.0-branch3/source/eduni/simdiag/GraphClearObject.java branches/gridsim4.0-branch3/source/eduni/simdiag/GraphData.java branches/gridsim4.0-branch3/source/eduni/simdiag/GraphDiagram.java branches/gridsim4.0-branch3/source/eduni/simdiag/GraphDisplay.java branches/gridsim4.0-branch3/source/eduni/simdiag/GraphEqn.java branches/gridsim4.0-branch3/source/eduni/simdiag/GraphEventObject.java branches/gridsim4.0-branch3/source/eduni/simdiag/GraphListener.java branches/gridsim4.0-branch3/source/eduni/simdiag/GraphLoader.java branches/gridsim4.0-branch3/source/eduni/simdiag/GraphSetAxes.java branches/gridsim4.0-branch3/source/eduni/simdiag/GraphSetScale.java branches/gridsim4.0-branch3/source/eduni/simdiag/GraphWindow.java branches/gridsim4.0-branch3/source/eduni/simdiag/TimingDiagram.java branches/gridsim4.0-branch3/source/eduni/simdiag/TimingWindow.java branches/gridsim4.0-branch3/source/eduni/simdiag/TraceEventObject.java branches/gridsim4.0-branch3/source/eduni/simdiag/TraceListener.java branches/gridsim4.0-branch3/source/eduni/simdiag/TraceLoader.java branches/gridsim4.0-branch3/source/eduni/simdiag/TraceSaver.java branches/gridsim4.0-branch3/source/eduni/simdiag/Traceable.java branches/gridsim4.0-branch3/source/eduni/simdiag/package.html branches/gridsim4.0-branch3/source/eduni/simjava/ branches/gridsim4.0-branch3/source/eduni/simjava/Evqueue.java branches/gridsim4.0-branch3/source/eduni/simjava/Semaphore.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_accum.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_any_p.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_entity.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_event.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_exception.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_from_p.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_none_p.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_not_from_p.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_not_type_p.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_outfile.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_output.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_port.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_predicate.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_reporter.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_reportfile.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_stat.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_stat_exception.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_system.java branches/gridsim4.0-branch3/source/eduni/simjava/Sim_type_p.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/ branches/gridsim4.0-branch3/source/eduni/simjava/distributions/ContinuousGenerator.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/DiscreteGenerator.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Generator.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_bernoulli_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_beta_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_betaprime_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_binomial_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_cauchy_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_chisquare_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_erlang_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_f_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_gamma_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_geometric_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_invgamma_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_logistic_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_lognormal_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_negexp_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_normal_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_parameter_exception.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_pareto_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_pascal_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_poisson_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_random_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_tstudent_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_uniform_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/Sim_weibull_obj.java branches/gridsim4.0-branch3/source/eduni/simjava/distributions/package.html branches/gridsim4.0-branch3/source/eduni/simjava/package.html branches/gridsim4.0-branch3/source/gridsim/ branches/gridsim4.0-branch3/source/gridsim/ARGridResource.java branches/gridsim4.0-branch3/source/gridsim/ARObject.java branches/gridsim4.0-branch3/source/gridsim/ARPolicy.java branches/gridsim4.0-branch3/source/gridsim/ARSimpleSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/Accumulator.java branches/gridsim4.0-branch3/source/gridsim/AdvanceReservation.java branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java branches/gridsim4.0-branch3/source/gridsim/GridInformationService.java branches/gridsim4.0-branch3/source/gridsim/GridResource.java branches/gridsim4.0-branch3/source/gridsim/GridSim.java branches/gridsim4.0-branch3/source/gridsim/GridSimCore.java branches/gridsim4.0-branch3/source/gridsim/GridSimRandom.java branches/gridsim4.0-branch3/source/gridsim/GridSimShutdown.java branches/gridsim4.0-branch3/source/gridsim/GridSimStandardPE.java branches/gridsim4.0-branch3/source/gridsim/GridSimTags.java branches/gridsim4.0-branch3/source/gridsim/GridStatistics.java branches/gridsim4.0-branch3/source/gridsim/GridUser.java branches/gridsim4.0-branch3/source/gridsim/Gridlet.java branches/gridsim4.0-branch3/source/gridsim/GridletList.java branches/gridsim4.0-branch3/source/gridsim/IO_data.java branches/gridsim4.0-branch3/source/gridsim/Machine.java branches/gridsim4.0-branch3/source/gridsim/MachineList.java branches/gridsim4.0-branch3/source/gridsim/PERange.java branches/gridsim4.0-branch3/source/gridsim/PERangeList.java branches/gridsim4.0-branch3/source/gridsim/ParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/ParameterException.java branches/gridsim4.0-branch3/source/gridsim/ResGridlet.java branches/gridsim4.0-branch3/source/gridsim/ResGridletList.java branches/gridsim4.0-branch3/source/gridsim/ResourceCalendar.java branches/gridsim4.0-branch3/source/gridsim/ResourceCharacteristics.java branches/gridsim4.0-branch3/source/gridsim/ResourceUserList.java branches/gridsim4.0-branch3/source/gridsim/SSGridlet.java branches/gridsim4.0-branch3/source/gridsim/Sim_from_port.java branches/gridsim4.0-branch3/source/gridsim/SpaceShared.java branches/gridsim4.0-branch3/source/gridsim/Stat.java branches/gridsim4.0-branch3/source/gridsim/TimeShared.java branches/gridsim4.0-branch3/source/gridsim/auction/ branches/gridsim4.0-branch3/source/gridsim/auction/Auction.java branches/gridsim4.0-branch3/source/gridsim/auction/AuctionObserver.java branches/gridsim4.0-branch3/source/gridsim/auction/AuctionTags.java branches/gridsim4.0-branch3/source/gridsim/auction/Auctioneer.java branches/gridsim4.0-branch3/source/gridsim/auction/ContinuousDoubleAuction.java branches/gridsim4.0-branch3/source/gridsim/auction/DoubleAuction.java branches/gridsim4.0-branch3/source/gridsim/auction/DutchAuction.java branches/gridsim4.0-branch3/source/gridsim/auction/EnglishAuction.java branches/gridsim4.0-branch3/source/gridsim/auction/FirstPriceSealedBidAuction.java branches/gridsim4.0-branch3/source/gridsim/auction/Message.java branches/gridsim4.0-branch3/source/gridsim/auction/MessageAsk.java branches/gridsim4.0-branch3/source/gridsim/auction/MessageBid.java branches/gridsim4.0-branch3/source/gridsim/auction/MessageCallForBids.java branches/gridsim4.0-branch3/source/gridsim/auction/MessageInformOutcome.java branches/gridsim4.0-branch3/source/gridsim/auction/MessageInformStart.java branches/gridsim4.0-branch3/source/gridsim/auction/MessageRejectBid.java branches/gridsim4.0-branch3/source/gridsim/auction/MessageRejectCallForBid.java branches/gridsim4.0-branch3/source/gridsim/auction/OneSidedAuction.java branches/gridsim4.0-branch3/source/gridsim/auction/Responder.java branches/gridsim4.0-branch3/source/gridsim/auction/ReverseDutchAuction.java branches/gridsim4.0-branch3/source/gridsim/auction/ReverseEnglishAuction.java branches/gridsim4.0-branch3/source/gridsim/auction/ReverseFirstPriceSealedBidAuction.java branches/gridsim4.0-branch3/source/gridsim/auction/package.html branches/gridsim4.0-branch3/source/gridsim/datagrid/ branches/gridsim4.0-branch3/source/gridsim/datagrid/DataGridResource.java branches/gridsim4.0-branch3/source/gridsim/datagrid/DataGridTags.java branches/gridsim4.0-branch3/source/gridsim/datagrid/DataGridUser.java branches/gridsim4.0-branch3/source/gridsim/datagrid/DataGridlet.java branches/gridsim4.0-branch3/source/gridsim/datagrid/File.java branches/gridsim4.0-branch3/source/gridsim/datagrid/FileAttribute.java branches/gridsim4.0-branch3/source/gridsim/datagrid/ReplicaManager.java branches/gridsim4.0-branch3/source/gridsim/datagrid/SimpleReplicaManager.java branches/gridsim4.0-branch3/source/gridsim/datagrid/filter/ branches/gridsim4.0-branch3/source/gridsim/datagrid/filter/FileNameFilter.java branches/gridsim4.0-branch3/source/gridsim/datagrid/filter/Filter.java branches/gridsim4.0-branch3/source/gridsim/datagrid/filter/FilterDataResult.java branches/gridsim4.0-branch3/source/gridsim/datagrid/filter/package.html branches/gridsim4.0-branch3/source/gridsim/datagrid/index/ branches/gridsim4.0-branch3/source/gridsim/datagrid/index/AbstractRC.java branches/gridsim4.0-branch3/source/gridsim/datagrid/index/DataGIS.java branches/gridsim4.0-branch3/source/gridsim/datagrid/index/DataRegionalGIS.java branches/gridsim4.0-branch3/source/gridsim/datagrid/index/RegionalRC.java branches/gridsim4.0-branch3/source/gridsim/datagrid/index/TopRegionalRC.java branches/gridsim4.0-branch3/source/gridsim/datagrid/index/package.html branches/gridsim4.0-branch3/source/gridsim/datagrid/package.html branches/gridsim4.0-branch3/source/gridsim/datagrid/storage/ branches/gridsim4.0-branch3/source/gridsim/datagrid/storage/HarddriveStorage.java branches/gridsim4.0-branch3/source/gridsim/datagrid/storage/Storage.java branches/gridsim4.0-branch3/source/gridsim/datagrid/storage/TapeStorage.java branches/gridsim4.0-branch3/source/gridsim/datagrid/storage/package.html branches/gridsim4.0-branch3/source/gridsim/filter/ branches/gridsim4.0-branch3/source/gridsim/filter/FilterCreateAR.java branches/gridsim4.0-branch3/source/gridsim/filter/FilterGridlet.java branches/gridsim4.0-branch3/source/gridsim/filter/FilterQueryTimeAR.java branches/gridsim4.0-branch3/source/gridsim/filter/FilterResult.java branches/gridsim4.0-branch3/source/gridsim/filter/package.html branches/gridsim4.0-branch3/source/gridsim/gui/ branches/gridsim4.0-branch3/source/gridsim/gui/AllocationAction.java branches/gridsim4.0-branch3/source/gridsim/gui/AllocationListener.java branches/gridsim4.0-branch3/source/gridsim/gui/AllocationSubject.java branches/gridsim4.0-branch3/source/gridsim/gui/DetachedMagnifyingGlass.java branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java branches/gridsim4.0-branch3/source/gridsim/gui/GridletPanel.java branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java branches/gridsim4.0-branch3/source/gridsim/index/ branches/gridsim4.0-branch3/source/gridsim/index/AbstractGIS.java branches/gridsim4.0-branch3/source/gridsim/index/RegionalGIS.java branches/gridsim4.0-branch3/source/gridsim/index/package.html branches/gridsim4.0-branch3/source/gridsim/net/ branches/gridsim4.0-branch3/source/gridsim/net/BusLink.java branches/gridsim4.0-branch3/source/gridsim/net/FIFOScheduler.java branches/gridsim4.0-branch3/source/gridsim/net/FloodAdPack.java branches/gridsim4.0-branch3/source/gridsim/net/FloodingRouter.java branches/gridsim4.0-branch3/source/gridsim/net/InfoPacket.java branches/gridsim4.0-branch3/source/gridsim/net/Input.java branches/gridsim4.0-branch3/source/gridsim/net/Link.java branches/gridsim4.0-branch3/source/gridsim/net/NetPacket.java branches/gridsim4.0-branch3/source/gridsim/net/Output.java branches/gridsim4.0-branch3/source/gridsim/net/Packet.java branches/gridsim4.0-branch3/source/gridsim/net/PacketScheduler.java branches/gridsim4.0-branch3/source/gridsim/net/RIPAdPack.java branches/gridsim4.0-branch3/source/gridsim/net/RIPRouter.java branches/gridsim4.0-branch3/source/gridsim/net/RateControlledRouter.java branches/gridsim4.0-branch3/source/gridsim/net/RateControlledScheduler.java branches/gridsim4.0-branch3/source/gridsim/net/Router.java branches/gridsim4.0-branch3/source/gridsim/net/SCFQScheduler.java branches/gridsim4.0-branch3/source/gridsim/net/SimpleLink.java branches/gridsim4.0-branch3/source/gridsim/net/package.html branches/gridsim4.0-branch3/source/gridsim/package.html branches/gridsim4.0-branch3/source/gridsim/services/ branches/gridsim4.0-branch3/source/gridsim/services/AcquisitionPolicy.java branches/gridsim4.0-branch3/source/gridsim/services/MessageBody.java branches/gridsim4.0-branch3/source/gridsim/services/Negotiation.java branches/gridsim4.0-branch3/source/gridsim/services/NegotiationList.java branches/gridsim4.0-branch3/source/gridsim/services/NegotiationMessage.java branches/gridsim4.0-branch3/source/gridsim/services/NegotiationPolicy.java branches/gridsim4.0-branch3/source/gridsim/services/Provider.java branches/gridsim4.0-branch3/source/gridsim/services/ProviderCalendar.java branches/gridsim4.0-branch3/source/gridsim/services/ProviderCharacteristics.java branches/gridsim4.0-branch3/source/gridsim/services/ProvisioningPolicy.java branches/gridsim4.0-branch3/source/gridsim/services/Service.java branches/gridsim4.0-branch3/source/gridsim/services/ServiceAttributes.java branches/gridsim4.0-branch3/source/gridsim/services/ServiceGridTags.java branches/gridsim4.0-branch3/source/gridsim/services/ServiceGridlet.java branches/gridsim4.0-branch3/source/gridsim/services/ServiceList.java branches/gridsim4.0-branch3/source/gridsim/services/ServiceRequest.java branches/gridsim4.0-branch3/source/gridsim/services/ServiceRequestList.java branches/gridsim4.0-branch3/source/gridsim/services/ServiceRequestWorkload.java branches/gridsim4.0-branch3/source/gridsim/services/ServiceRequestWorkloadList.java branches/gridsim4.0-branch3/source/gridsim/services/ServiceRequester.java branches/gridsim4.0-branch3/source/gridsim/services/ServiceRequirement.java branches/gridsim4.0-branch3/source/gridsim/services/ServiceRequirementList.java branches/gridsim4.0-branch3/source/gridsim/services/ServiceWorkload.java branches/gridsim4.0-branch3/source/gridsim/services/ServiceWorkloadItem.java branches/gridsim4.0-branch3/source/gridsim/services/SimpleAcquisitionPolicy.java branches/gridsim4.0-branch3/source/gridsim/services/SimpleProvisionPolicy.java branches/gridsim4.0-branch3/source/gridsim/services/filter/ branches/gridsim4.0-branch3/source/gridsim/services/filter/ServiceFilter.java branches/gridsim4.0-branch3/source/gridsim/services/filter/ServiceNameFilter.java branches/gridsim4.0-branch3/source/gridsim/services/filter/ServiceNameTypeFilter.java branches/gridsim4.0-branch3/source/gridsim/services/filter/ServiceTypeFilter.java branches/gridsim4.0-branch3/source/gridsim/services/index/ branches/gridsim4.0-branch3/source/gridsim/services/index/GridServiceRepository.java branches/gridsim4.0-branch3/source/gridsim/services/index/RegionalGSR.java branches/gridsim4.0-branch3/source/gridsim/util/ branches/gridsim4.0-branch3/source/gridsim/util/NetworkReader.java branches/gridsim4.0-branch3/source/gridsim/util/Poisson.java branches/gridsim4.0-branch3/source/gridsim/util/SimReport.java branches/gridsim4.0-branch3/source/gridsim/util/TrafficGenerator.java branches/gridsim4.0-branch3/source/gridsim/util/Workload.java branches/gridsim4.0-branch3/source/gridsim/util/package.html Added: branches/gridsim4.0-branch3/.classpath =================================================================== --- branches/gridsim4.0-branch3/.classpath (rev 0) +++ branches/gridsim4.0-branch3/.classpath 2007-09-14 07:33:33 UTC (rev 58) @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="source"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="src" path="examples"/> + <classpathentry kind="output" path="bin"/> +</classpath> Added: branches/gridsim4.0-branch3/.project =================================================================== --- branches/gridsim4.0-branch3/.project (rev 0) +++ branches/gridsim4.0-branch3/.project 2007-09-14 07:33:33 UTC (rev 58) @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>gridsim-sf</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> Added: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExample01.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExample01.java (rev 0) +++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExample01.java 2007-09-14 07:33:33 UTC (rev 58) @@ -0,0 +1,176 @@ + +package examples.workload.parallel; + +import gridsim.GridResource; +import gridsim.GridSim; +import gridsim.Machine; +import gridsim.MachineList; +import gridsim.ResourceCharacteristics; +import gridsim.util.Workload; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.LinkedList; +import java.util.Random; + + +/** + * Test Driver class for this example + */ +public class TurboExample01 +{ + /** + * Creates main() to run this example + */ + public static void main(String[] args) + { + long startTime = System.currentTimeMillis(); + if(args.length == 0){ + System.out.println("Please provide the location of the workload file!"); + System.exit(1); + } + + try { + + ////////////////////////////////////////// + // Get the workload to be used The format should be: + // ASCII text, gzip or zip. + + String fileName = args[0]; + // /Users/marcosd/Documents/workspace/intergrid/workloads/sdsc_blue_2000_400.swf + + ArrayList<GridResource> resources = new ArrayList<GridResource>(); + + ////////////////////////////////////////// + // 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 run-time exception + // error. + + // number of grid user entities + any Workload entities. + int num_user = 1; + Calendar calendar = Calendar.getInstance(); + boolean trace_flag = false; // mean trace GridSim events + + // Initialize the GridSim package without any statistical + // functionalities. Hence, no GridSim_stat.txt file is created. + System.out.println("Initializing GridSim package"); + GridSim.init(num_user, calendar, trace_flag); + + ////////////////////////////////////////// + // Creates one or more GridResource entities + int totalResource = 1; // total number of Grid resources + int rating = 377; // rating of each PE in MIPS + int totalPE = 9; // total number of PEs for each Machine + int totalMachine = 128; // total number of Machines + int i = 0; + + String[] resArray = new String[totalResource]; + for (i = 0; i < totalResource; i++) + { + String resName = "Res_" + i; + GridResource resource = createGridResource(resName, rating, totalMachine, totalPE); + resources.add(resource); + + // add a resource name into an array + resArray[i] = resName; + } + + ////////////////////////////////////////// + // Creates one Workload trace entity. + + int resID = 0; + Random r = new Random(); + resID = r.nextInt(totalResource); + Workload workload = new Workload("Load_1", fileName, resArray[resID], rating); + + ////////////////////////////////////////// + // Starts the simulation in debug mode + GridSim.startGridSimulation(true); + + // Start the simulation in normal mode +// GridSim.startGridSimulation(); + + ////////////////////////////////////////// + // Final step: Prints the Gridlets when simulation is over + long finishTime = System.currentTimeMillis(); + System.out.println("The simulation took " + (finishTime - startTime) + " milliseconds"); + + // prints the Gridlets inside a Workload entity + // workload.printGridletList(trace_flag); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Creates one Grid resource. A Grid resource contains one or more + * Machines. Similarly, a Machine contains one or more PEs (Processing + * Elements or CPUs). + * @param name a Grid Resource name + * @param peRating rating of each PE + * @param totalMachine total number of Machines + * @param totalPE total number of PEs for each Machine + */ + private static GridResource createGridResource(String name, int peRating, + int totalMachine, int totalPE) + { + + ////////////////////////////////////////// + // 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++) + { + ////////////////////////////////////////// + // 4. Create one Machine with its id and list of PEs or CPUs + mList.add( new Machine(i, totalPE, peRating) ); + } + + ////////////////////////////////////////// + // 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 = "Sun Ultra"; // system architecture + String os = "Solaris"; // operating system + double time_zone = 0.0; // time zone this resource located + double cost = 3.0; // the cost of using this resource + + ResourceCharacteristics resConfig = new ResourceCharacteristics( + arch, os, mList, ResourceCharacteristics.PARALLEL_SPACE_SHARED, + time_zone, cost); + + ////////////////////////////////////////// + // 6. Finally, we need to create a GridResource object. + double baud_rate = 10000.0; // communication speed + 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 { + gridRes = new GridResource(name, baud_rate, seed, + resConfig, peakLoad, offPeakLoad, holidayLoad, Weekends, + Holidays); + } + catch (Exception e) { + e.printStackTrace(); + } + + System.out.println("Creates one Grid resource with name = " + name); + return gridRes; + } +} // end class + Added: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphClearObject.java =================================================================== --- branches/gridsim4.0-branch3/source/eduni/simdiag/GraphClearObject.java (rev 0) +++ branches/gridsim4.0-branch3/source/eduni/simdiag/GraphClearObject.java 2007-09-14 07:33:33 UTC (rev 58) @@ -0,0 +1,7 @@ +package eduni.simdiag; + +/** Clears graph */ +public class GraphClearObject extends GraphEventObject { + public GraphClearObject(Object src) { super(src); } + public void doit(GraphDiagram d) { d.clear(); } +} Property changes on: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphClearObject.java ___________________________________________________________________ Name: svn:executable + * Added: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphData.java =================================================================== --- branches/gridsim4.0-branch3/source/eduni/simdiag/GraphData.java (rev 0) +++ branches/gridsim4.0-branch3/source/eduni/simdiag/GraphData.java 2007-09-14 07:33:33 UTC (rev 58) @@ -0,0 +1,39 @@ +package eduni.simdiag; + +import java.util.StringTokenizer; + +/** Stores a single data point. + * + * Each data point has a line name and X and Y coordinates. + */ +public class GraphData extends GraphEventObject { + public String linename; + public double x,y; + + /** Constructs data elem from a single text line + * Format: linename x y + * e.g. "total_time 10 123.45" + */ + public GraphData(Object src, String l) { + super(src); + StringTokenizer st = new StringTokenizer(l, " "); + try { + linename = st.nextToken(); + x = (Double.valueOf(st.nextToken())).doubleValue(); + y = (Double.valueOf(st.nextToken())).doubleValue(); + } catch( Exception e) { + System.out.println("Graphdata Couldn't parse "+l); + } + } + + /** Constructs data elem from linename, x and y + */ + public GraphData(Object src, String linename, double x, double y){ + super(src); + this.linename = linename; + this.x = x; this.y = y; + } + + /** Called by recipient to implement command */ + public void doit(GraphDiagram d) { d.data(linename,x,y); } +} Property changes on: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphData.java ___________________________________________________________________ Name: svn:executable + * Added: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphDiagram.java =================================================================== --- branches/gridsim4.0-branch3/source/eduni/simdiag/GraphDiagram.java (rev 0) +++ branches/gridsim4.0-branch3/source/eduni/simdiag/GraphDiagram.java 2007-09-14 07:33:33 UTC (rev 58) @@ -0,0 +1,353 @@ +/** + * GraphDiagram.java + * simjava graph + */ + +package eduni.simdiag; + +import java.util.List; +import java.util.ArrayList; +import java.awt.Panel; +import java.awt.Graphics; +import java.awt.Dimension; +import java.awt.Image; +import java.awt.Color; +import java.awt.GridLayout; +import java.awt.Frame; +import java.applet.Applet; + +class DPoint { + public double x,y; + public DPoint(double xx, double yy) {x=xx;y=yy;} +} + +class Linedata { + String name; + List points = new ArrayList();// list of points + public Linedata(String n) { name = n; } + public void add(double x, double y) { + points.add(new DPoint(x,y)); + } + public DPoint getDPoint(int i) { return (DPoint)points.get(i); } + public String getName() { return name; } + Color valtocol(int v) { + if (v==0) return Color.blue; + if (v==1) return Color.red; + if (v==2) return Color.darkGray; + if (v==3) return Color.gray; + if (v==4) return Color.green; + if (v==5) return Color.lightGray; + if (v==6) return Color.magenta; + if (v==7) return Color.orange; + if (v==8) return Color.pink; + if (v==9) return Color.cyan; + return valtocol(v%10); + } + + public void draw(Graphics g, int i, GraphPanel p) { + g.setColor(valtocol(i)); + // Join points. + for (int j=0; j<points.size()-1; j++) { + DPoint p1 = (DPoint)points.get(j); + DPoint p2 = (DPoint)points.get(j+1); + g.drawLine(p.xscale(p1.x),p.yscale(p1.y), + p.xscale(p2.x),p.yscale(p2.y)); + } + + int sz = 2; // Cross size. + for (int j=0; j<points.size(); j++) { + DPoint p1 = (DPoint)points.get(j); + int ix = p.xscale(p1.x); + int iy = p.yscale(p1.y); + g.drawLine(ix-sz,iy-sz,ix+sz,iy+sz); + g.drawLine(ix+sz,iy-sz,ix-sz,iy+sz); + } + + // Draw Key (tr) + int kyspc = 20; int kx = p.getSize().width - 100; + int ky = (i+2) * kyspc; + g.drawLine(kx,ky,kx+10,ky); + g.drawString(name,kx+10,ky); + } +} + +class GraphPanel extends Panel { + String xax="X",yax="Y"; + List data = new ArrayList(); // List of Linedata + double xmin=0.0, xmax=1.0, ymin=0.0, ymax=1.0; + // Offset of axes + int xoff = 40; + int yoff = 40; + + /** Return linedata given line name, or null if not found */ + Linedata getLine(String n) { + for (int i=0; i<data.size(); i++) { + Linedata ld = (Linedata)data.get(i); + if (n.compareTo(ld.getName())==0) + return ld; + } + return null; + } + GraphPanel() { + super(); + resetScale(); + } + void resetScale() { + xmin=0.0; + xmax=1.0; + ymin=0.0; + ymax=1.0; + } + + public int xscale(double x) { + int w = getSize().width; + return (int)(((x-xmin)/(xmax-xmin)) * (w-xoff)) + xoff; + } + public int yscale(double y) { + int h = getSize().height; + return h-((int)(((y-ymin)/(ymax-ymin)) * (h-yoff)) + yoff); + } + public void clear() { + data.clear(); + resetScale(); + } + + public void setAxes(String xax, String yax) { + this.xax = xax; this.yax = yax; + } + + public void setScale(double xmin,double xmax, double ymin, double ymax) { + this.xmin = xmin; + this.xmax = xmax; + this.ymin = ymin; + this.ymax = ymax; + } + + public void data(String linename, double x, double y) { + Linedata ld = getLine(linename); + if (ld==null) { + ld = new Linedata(linename); + data.add(ld); + } + ld.add(x,y); + if (x > xmax) xmax = x; + if (y > ymax) ymax = y; + if (x < xmin) xmin = x; + if (y < ymin) ymin = y; + } + + public void display() { + repaint(); + } + + double log10(double d) { + return Math.log(d)/Math.log(10); + } + + void drawNotches(Graphics g, int x1, int y1, int x2, int y2, + double v1, double v2) { + boolean isXaxis = (y1==y2); + double tsize = v2 - v1; // e.g. 17.2 + double tgaplog = log10( (double) tsize ); // e.g. 1.2ish + int tgaprounded = (int)tgaplog; // e.g. 1 + double tgapfinal = Math.pow( 10.0, (double) tgaprounded ); // e.g.10.0 + // Change to 0 5 10 etc? + if (tsize/tgapfinal < 3.0) { tgapfinal /= 2.0; } + + // Get first point + double div = 0.5 + (v1 / tgapfinal); + int idiv = (int) div; + double firstt1 = idiv * tgapfinal; + + // Draw major notches + if (isXaxis) { + int notchHeight = yoff/10; + for (double t=firstt1; t<=v2; t+=tgapfinal ) { + int xp = xscale(t); + String s = Double.toString(t); + g.setColor(Color.blue); + g.drawLine(xp,y1,xp,notchHeight+y1); + int w = g.getFontMetrics().stringWidth(s); + int h = g.getFontMetrics().getHeight(); + g.drawString(s,xp-w/2,y1+notchHeight+h); + + g.setColor(Color.gray.brighter()); + g.drawLine(xp,y1,xp,0); + } + } else { + int notchHeight = xoff/10; + for (double t=firstt1; t<=v2; t+=tgapfinal ) { + int yp = yscale(t); + String s = Double.toString(t); + g.setColor(Color.blue); + g.drawLine(x1,yp,x1-notchHeight,yp); + int sw = g.getFontMetrics().stringWidth(s); + int sh = g.getFontMetrics().getHeight(); + g.drawString(s,x1-sw-notchHeight,yp+sh/2); + + g.setColor(Color.gray.brighter()); + g.drawLine(x1,yp,getSize().width,yp ); + } + } + + } + + void drawAxes(Graphics g ) { + int w = getSize().width; + int h = getSize().height; + + g.setColor(Color.blue); + g.drawLine(xoff, h-yoff, w, h-yoff); + g.drawLine(xoff, h-yoff, xoff, 0); + g.drawString(xax,w/2,h-yoff/3); + g.drawString(yax,xoff/3,h/2); + + // Draw notches + drawNotches(g,xoff, h-yoff, w, h-yoff,xmin,xmax); + drawNotches(g,xoff, h-yoff, xoff, 0 ,ymin,ymax); + + g.setColor(Color.blue.brighter()); + g.drawLine(xoff, h-yoff+1, w, h-yoff+1); + g.drawLine(xoff+1, h-yoff, xoff+1, 0); + } + + + Image offscreen; + Dimension offscreensize=new Dimension(); + Graphics offg; + + /** Plot the graph */ + public void paint(Graphics g) { + Dimension d = getSize(); + if ((offscreen == null) || (d.width != offscreensize.width) || (d.height != offscreensize.height)) { + offscreen = createImage(d.width, d.height); + offscreensize = d; + offg = offscreen.getGraphics(); + } + + int w = getSize().width; + int h = getSize().height; + System.out.println("Painting "+w+" "+h); + offg.setColor(Color.lightGray.darker()); + offg.fillRect(0,0,w,h); + offg.setColor(Color.lightGray); + offg.fillRect(xoff,0,w,h-yoff); + drawAxes(offg); + + for (int i=0; i<data.size(); i++) { + Linedata ld = (Linedata)data.get(i); + ld.draw(offg,i,this); + } + g.drawImage(offscreen, 0, 0, null); + } +} + +/** + * This class represents the graph application. + * @version 1.0, July 1997 + * @author Fred Howell + */ +public class GraphDiagram extends Applet implements GraphListener, Runnable { + transient Thread thread; + + GraphPanel diag; + + /** Constructs a graph which runs in its own thread. + */ + public GraphDiagram() { + super(); + thread = new Thread(this); + thread.start(); + } + + /** Draws graph */ + public void run() { + init(); + } + /** Graph beans event interface */ + private List graphListeners = new ArrayList(); + + /** Adds a graph listener to the output. */ + public synchronized void addGraphListener(GraphListener l) { + graphListeners.add(l); + } + /** Removes a graph listener from the output. */ + public synchronized void removeGraphListener(GraphListener l) { + graphListeners.remove(l); + } + /** Deals with incoming graph events */ + public void handleGraph(GraphEventObject e) { + e.doit(this); + forwardGraph(e); + } + /** Sends graph events to any listeners */ + public void forwardGraph(GraphEventObject e) { + List l; + synchronized(this) { l = (List)((ArrayList)graphListeners).clone(); } + // GraphEventObject teo = new GraphEventObject(this,e); + // Not bothering to clone the object, make sure sender doesn't change + // it. + for (int i=0; i<l.size(); i++) { + GraphListener tl = (GraphListener) l.get(i); + tl.handleGraph(e); + } + } + + /** Sets up graph diagram display */ + public void init() { + setLayout(new GridLayout(1,1)); + diag = new GraphPanel(); + add(diag); + } + + /** Returns the panel associated with this graph */ + public GraphPanel get_diag() { return diag; } + + /** Clears the graph */ + public void clear() { + diag.clear(); + diag.repaint(); + } + + /** Sets the axes labels */ + public void setAxes(String xax, String yax) { + System.out.println("Setting axes to "+xax+" "+yax); + diag.setAxes(xax,yax); + } + + /** Sets the scale */ + public void setScale(double xmin,double xmax, double ymin, double ymax) { + diag.setScale(xmin,xmax,ymin,ymax); + } + + /** Adds a data element */ + public void data(String linename, double x, double y) { + System.out.println("Data "+linename+" "+x+" "+y); + diag.data(linename,x,y); + } + + /** Displays the graph */ + public void display() { + diag.repaint(); + } + + + /** Constructs an example using the graph, by connecting a + * GraphEqn object to its input to display sine waves. + */ + public static void main(String args[]) { + Frame f = new Frame("Graph Diagram Example"); + GraphDiagram ex1 = new GraphDiagram(); + // GraphLoader tl = new GraphLoader("file:/home/fwh/export/tmp.graph"); + // tl.addGraphListener(ex1); + // tl.startLoading(); + GraphEqn ge = new GraphEqn(); + ge.addGraphListener(ex1); + ge.startRunning(); + + f.add("Center", ex1); + f.pack(); + f.setSize(600,300); + f.show(); + } +} Property changes on: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphDiagram.java ___________________________________________________________________ Name: svn:executable + * Added: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphDisplay.java =================================================================== --- branches/gridsim4.0-branch3/source/eduni/simdiag/GraphDisplay.java (rev 0) +++ branches/gridsim4.0-branch3/source/eduni/simdiag/GraphDisplay.java 2007-09-14 07:33:33 UTC (rev 58) @@ -0,0 +1,10 @@ +package eduni.simdiag; + +/** Displays graph. Required to update the display after + * a set of <a href="eduni.simdiag.GraphData.html">GraphData</a> commands. + * see also <a href="../design_doc/index.html#twodgraphs">the design document</a>. + */ +public class GraphDisplay extends GraphEventObject { + public GraphDisplay(Object src) { super(src); } + public void doit(GraphDiagram d) { d.display(); } +} Property changes on: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphDisplay.java ___________________________________________________________________ Name: svn:executable + * Added: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphEqn.java =================================================================== --- branches/gridsim4.0-branch3/source/eduni/simdiag/GraphEqn.java (rev 0) +++ branches/gridsim4.0-branch3/source/eduni/simdiag/GraphEqn.java 2007-09-14 07:33:33 UTC (rev 58) @@ -0,0 +1,76 @@ +package eduni.simdiag; + +import java.util.List; +import java.util.ArrayList; +import java.applet.Applet; + +/** + * Generates sin/cos graph from equation. + * The output format is a stream of + * GraphEventObjects which can be read and displayed by + * a GraphDiagram. + * This class may be useful as an example of how to + * generate a graph from user simulations: + * see the <a href="../../eduni/simdiag/GraphEqn.java">source code</a> + */ + +public class GraphEqn implements Runnable { + + transient Thread thread; + + /** Creates a graph generator (Sine, Cos) */ + public GraphEqn() { + } + + /** Called after output has been wired */ + public void startRunning() { + thread = new Thread(this); + thread.start(); + } + + /** Generates the graph */ + public void run() { + double delta = 0.1; + // while (true) { + forwardGraph( new GraphClearObject(this) ); + + forwardGraph( new GraphSetAxes(this,"X","Y") ); + + for (double x = 0.0; x<20; x+=0.1) { + forwardGraph( new GraphData(this,"sin",x,Math.sin(x+delta)) ); + forwardGraph( new GraphData(this,"cos",x,Math.cos(x+delta)) ); + + forwardGraph( new GraphDisplay(this) ); + try { thread.sleep(100); } catch (Exception e) {} + } + + forwardGraph( new GraphDisplay(this) ); + delta += 0.1; + // try { thread.sleep(1000); } catch (Exception e) {} + // } + } + + /** Javabeans graph event output: List of + * event listeners. + */ + private List graphListeners = new ArrayList(); + /** Adds a graph listener */ + public synchronized void addGraphListener(GraphListener l) { + graphListeners.add(l); + } + /** Removes a graph listener */ + public synchronized void removeGraphListener(GraphListener l) { + graphListeners.remove(l); + } + /** Forwards a graph event to anyone listening. + */ + public void forwardGraph(GraphEventObject e) { + List l; + // GraphEventObject weo = new GraphEventObject(this,e); + synchronized(this) { l = (List)((ArrayList)graphListeners).clone(); } + for (int i=0; i<l.size(); i++) { + GraphListener wl = (GraphListener) l.get(i); + wl.handleGraph(e); + } + } +} Property changes on: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphEqn.java ___________________________________________________________________ Name: svn:executable + * Added: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphEventObject.java =================================================================== --- branches/gridsim4.0-branch3/source/eduni/simdiag/GraphEventObject.java (rev 0) +++ branches/gridsim4.0-branch3/source/eduni/simdiag/GraphEventObject.java 2007-09-14 07:33:33 UTC (rev 58) @@ -0,0 +1,26 @@ +package eduni.simdiag; + +import java.util.EventObject; + +/** + * The basic graph event class. + * All graph commands are derived from this and override + * the doit() method. + * @see eduni.simdiag.GraphData + * @see eduni.simdiag.GraphDisplay + * @see eduni.simdiag.GraphSetAxes + * @see eduni.simdiag.GraphSetScale + * @see eduni.simdiag.GraphClearObject + */ + +public class GraphEventObject extends EventObject { + public GraphEventObject(Object src) { + super(src); + } + /** Implements graph commands. + * The graph commands override this to do their biz. + */ + public void doit(GraphDiagram d) { + System.out.println("Executing a basic command\n"); + } +} Property changes on: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphEventObject.java ___________________________________________________________________ Name: svn:executable + * Added: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphListener.java =================================================================== --- branches/gridsim4.0-branch3/source/eduni/simdiag/GraphListener.java (rev 0) +++ branches/gridsim4.0-branch3/source/eduni/simdiag/GraphListener.java 2007-09-14 07:33:33 UTC (rev 58) @@ -0,0 +1,14 @@ +package eduni.simdiag; + +import java.util.EventListener; + +/** + * Graph event listener interface. <p> + * Implemented by graph drawing routine. + * @see eduni.simdiag.GraphDiagram + */ + +public interface GraphListener extends EventListener { + /** Responds to a single graph event */ + void handleGraph(GraphEventObject teo); +} Property changes on: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphListener.java ___________________________________________________________________ Name: svn:executable + * Added: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphLoader.java =================================================================== --- branches/gridsim4.0-branch3/source/eduni/simdiag/GraphLoader.java (rev 0) +++ branches/gridsim4.0-branch3/source/eduni/simdiag/GraphLoader.java 2007-09-14 07:33:33 UTC (rev 58) @@ -0,0 +1,99 @@ +/* GraphLoader.java */ + +package eduni.simdiag; + +import java.util.List; +import java.util.ArrayList; +import java.util.EventListener; +import java.applet.Applet; +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; + +/** + * Converts graph from URL to GraphEventListener format. + */ +public class GraphLoader implements Runnable { + + transient Thread thread; + String urlName; + + + /** Create a graph loader with the given url */ + public GraphLoader(String urlName) { + this.urlName = urlName; + thread = new Thread(this); + } + + /** Called after output has been wired */ + public void startLoading() { + thread.start(); + } + + protected String nextLine(BufferedReader r) { + try { + String l = r.readLine(); + return l; + } catch (Exception e) { + return null; + } + } + + public void run() { + URL u; + try { + u = new URL(urlName); + } catch (Exception e) { + System.out.println("Can't open URL "+urlName); + return; + } + + DataInputStream file; + try { + file = new DataInputStream(u.openStream()); + } catch (IOException ioe) { + System.out.println("Couldn't open URL\n"); + return; + } + BufferedReader in = new BufferedReader(new InputStreamReader(file)); + String l; + + int numevents = 0; + + forwardGraph( new GraphClearObject(this) ); + // File fmt: + // axis names, data. + // mem speed\n time\n sys1 10 123.4 etc + String xax = nextLine(in); + String yax = nextLine(in); + forwardGraph( new GraphSetAxes(this,xax,yax) ); + while ((l = nextLine(in))!=null) { + forwardGraph( new GraphData(this,l) ); + numevents += 1; + } + + forwardGraph( new GraphDisplay(this) ); + + System.out.println("Read in "+numevents+" lines"); + } + + /* Javabeans graph event output */ + private List graphListeners = new ArrayList(); + public synchronized void addGraphListener(GraphListener l) { + graphListeners.add(l); + } + public synchronized void removeGraphListener(GraphListener l) { + graphListeners.remove(l); + } + public void forwardGraph(GraphEventObject e) { + List l; + // GraphEventObject weo = new GraphEventObject(this,e); + synchronized(this) { l = (List)((ArrayList)graphListeners).clone(); } + for (int i=0; i<l.size(); i++) { + GraphListener wl = (GraphListener) l.get(i); + wl.handleGraph(e); + } + } +} Property changes on: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphLoader.java ___________________________________________________________________ Name: svn:executable + * Added: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphSetAxes.java =================================================================== --- branches/gridsim4.0-branch3/source/eduni/simdiag/GraphSetAxes.java (rev 0) +++ branches/gridsim4.0-branch3/source/eduni/simdiag/GraphSetAxes.java 2007-09-14 07:33:33 UTC (rev 58) @@ -0,0 +1,21 @@ +package eduni.simdiag; + +/** Stores a command to set the axes labels for this graph. + * + */ +public class GraphSetAxes extends GraphEventObject { + String xax,yax; + /** Constructs a setaxes command. + * @param xax The label of the X axis. + * @param yax The label of the Y axis. + */ + + public GraphSetAxes(Object src, String xax, String yax){ + super(src); + this.xax = xax; this.yax=yax; + } + /** Sets the axes labels of the given diagram. + * Called by the recipient of the command. + */ + public void doit(GraphDiagram d) { d.setAxes(xax,yax); } +} Property changes on: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphSetAxes.java ___________________________________________________________________ Name: svn:executable + * Added: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphSetScale.java =================================================================== --- branches/gridsim4.0-branch3/source/eduni/simdiag/GraphSetScale.java (rev 0) +++ branches/gridsim4.0-branch3/source/eduni/simdiag/GraphSetScale.java 2007-09-14 07:33:33 UTC (rev 58) @@ -0,0 +1,14 @@ +package eduni.simdiag; + +/** Sets scale */ +public class GraphSetScale extends GraphEventObject { + double xmin,xmax,ymin,ymax; + public GraphSetScale(Object src, double xmin,double xmax, double ymin, double ymax) { + super(src); + this.xmin = xmin; + this.xmax = xmax; + this.ymin = ymin; + this.ymax = ymax; + } + public void doit(GraphDiagram d) { d.setScale(xmin,xmax,ymin,ymax); } +} Property changes on: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphSetScale.java ___________________________________________________________________ Name: svn:executable + * Added: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphWindow.java =================================================================== --- branches/gridsim4.0-branch3/source/eduni/simdiag/GraphWindow.java (rev 0) +++ branches/gridsim4.0-branch3/source/eduni/simdiag/GraphWindow.java 2007-09-14 07:33:33 UTC (rev 58) @@ -0,0 +1,33 @@ +package eduni.simdiag; + +import java.awt.Frame; + +/** A graph diagram in a separate window (and thread). + * <b>Note</b> that it is the GraphDiagram which listens + * to graph event objects, not the GraphWindow. + * + * Usage (from a class which generates GraphObjects) + * <pre> + * GraphWindow gw = new GraphWindow(); + * addGraphListener( gw.getDiag()); + * gw.start(); + * </pre> + */ +public class GraphWindow extends Thread { + Frame f; + GraphDiagram td; + + public GraphWindow() { + f = new Frame("Graph Diagram"); + td = new GraphDiagram(); + } + /** Displays the window */ + public void run() { + // td.init(); + f.add(td); + f.pack(); + f.setVisible(true); + } + /** Returns the graph diagram for this window */ + public GraphDiagram getDiag() { return td; } +} Property changes on: branches/gridsim4.0-branch3/source/eduni/simdiag/GraphWindow.java ___________________________________________________________________ Name: svn:executable + * Added: branches/gridsim4.0-branch3/source/eduni/simdiag/TimingDiagram.java =================================================================== --- branches/gridsim4.0-branch3/source/eduni/simdiag/TimingDiagram.java (rev 0) +++ branches/gridsim4.0-branch3/source/eduni/simdiag/TimingDiagram.java 2007-09-14 07:33:33 UTC (rev 58) @@ -0,0 +1,806 @@ +/** + * TimingDiagram.java + * simjava timing diagram + * Adapted from a C++/Motif version + * 31 Jan 1998 - making it run in its own thread (so it + * doesn't need its own window). + */ + +package eduni.simdiag; + +import java.util.List; +import java.util.ArrayList; +import java.util.StringTokenizer; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Panel; +import java.awt.Button; +import java.awt.Image; +import java.awt.Dimension; +import java.awt.Scrollbar; +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; +import java.awt.Frame; +import java.awt.Font; +import java.applet.Applet; +import java.awt.event.InputEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseMotionListener; +import java.awt.event.MouseListener; +import java.awt.event.AdjustmentListener; +import java.awt.event.ActionEvent; +import java.awt.event.MouseEvent; +import java.awt.event.AdjustmentEvent; + +class StringVector { + protected List v; + StringVector() { v = new ArrayList(); } + List getV() { return v; } + void add(String s) { v.add(s); } + String get( int i ) { return (String)v.get(i); } + int find( String s ) { + String found = null, curr; + int foundi = 0; + int v_size = v.size(); + for (int i=0; i < v_size; i++) { + curr = (String)v.get(i); + if(s.compareTo(curr) == 0) { + found = curr; + foundi = i; + } + } + return foundi; + } +} + +/** + * This class represents a data type to be displayed in + * The timing diagram. + * @version 1.0, June 1997 + * @author Fred Howell + */ +class TypeParam { + String typename; + protected StringVector labels; + TypeParam(String buff) { + labels = new StringVector(); + StringTokenizer st = new StringTokenizer(buff, " "); + typename = st.nextToken(); + while (st.hasMoreTokens()) + labels.add(st.nextToken()); + } + String getLabel(int i) { return labels.get(i); } + int get_index(String l) { return labels.find(l); } + + Color valtocol(int v) { + if (v==0) return Color.blue; + if (v==1) return Color.cyan; + if (v==2) return Color.darkGray; + if (v==3) return Color.gray; + if (v==4) return Color.green; + if (v==5) return Color.lightGray; + if (v==6) return Color.magenta; + if (v==7) return Color.orange; + if (v==8) return Color.pink; + if (v==9) return Color.red; + if (v==10) return Color.white; + return valtocol(v%10); + } + void drawKey(Graphics g, int x, int y, int w, int h) { + g.setColor(Color.black); + g.drawString(typename,x,y+h); + + // Draw blocks for labels too + String curr; + int blksize = 20; + List labelsV = labels.getV(); + int labelsV_size = labelsV.size(); + for (int i=0; i < labelsV_size; i++) { + int keywidth = w / (labelsV_size+1); + curr = (String)labelsV.get(i); + g.setColor(Color.black); + g.drawString(curr,x + (i+1)*keywidth, y+h); + g.setColor(valtocol(i)); + g.fillRect(x + (i+1)*keywidth, y , keywidth, h/2); + } + } +} + +class Types { + protected List types; + Types() { types = new ArrayList(); } + void add(TypeParam tp) { types.add(tp); } + TypeParam find( String s ) { + TypeParam found = null, curr; + int foundi = 0; + int types_size = types.size(); + for (int i=0; i < types_size; i++) { + curr = (TypeParam)types.get(i); + if(s.compareTo(curr.typename) == 0) { + found = curr; + } + } + return found; + } + void drawKeys(Graphics g, int w, int h) { + TypeParam curr; + int types_size = types.size(); + for (int i=0; i < types_size; i++) { + int keyheight = h / types_size; + curr = (TypeParam)types.get(i); + curr.drawKey(g,0,i * keyheight, w, (int)(keyheight*0.7)); + } + } + List getV() { return types; } +} + +class Event { + double time; + int stateno; + Event() { time = -1; stateno = 0; } + Event(double t, int s) { time = t; stateno = s; } + boolean isblank() { return (time==-1); } +} + + +/** + * This class represents an entry on the diagram + * including all data. + * @version 1.0, June 1997 + * @author Fred Howell + */ +class Entry { + + protected String name; + protected List events; + protected TypeParam tp; + int x,y,w,h; + double startt, endt; + + Entry(String n, TypeParam tp) { + name = n; + events = new ArrayList(); + this.tp = tp; + x = 0; y = 0; w = 100; h = 100; + } + + TypeParam getType() { return tp; } + void add(Event e) { events.add(e); } + void setPosition(int x, int y, int w, int h) { + this.x = x; + this.y = y; + this.w = w; + this.h = h; + } + + int ttox(double t ) { + return (int)((w) * (t-startt)/(endt-startt)); + } + + Color valtocol(int v) { + return tp.valtocol(v); + } + + void drawLabel(Graphics g, int x, int y) { + // Draw label + g.setColor(Color.black); + g.drawString(name,x,y); + } + + // draw all events from t1 to t2. + void draw(Graphics g, double t1, double t2) { + startt = t1; endt = t2; + + // System.out.println("Drawing from "+t1+" to "+t2); + + // Get last event before starttime + int ptri=0, previ=0; + boolean found = false; + int i=0; + for (i=0; i<events.size() && !found; i++) { + if (((Event)events.get(i)).time > t1) { + found = true; + ptri = i; + previ = ptri-1; if (previ<0) previ=0; + } + } + + // System.out.println("Found start at index "+previ+" out of "+events.size()); + + boolean reachedend = false; + for (; previ<events.size() && !reachedend; previ++) { + double time1=t1,time2=t2; + int val = 0; + + ptri = previ+1; + + Event prevevent = (Event)events.get(previ); + Event ptr; + if (ptri<events.size()) + ptr = (Event)events.get(ptri); + else ptr = new Event(); + + if (!prevevent.isblank()) { + time1 = prevevent.time; + val = prevevent.stateno; + } + if (!ptr.isblank()) time2 = ptr.time; + + if (time2 > t2) time2 = t2; + if (time1 > t2) time1 = t2; + + //System.out.println("Drawing: "+ttox(time1)+" "+ttox(time2-time1)+" v="+val+" t="+time1+" - "+time2); + + g.setColor(valtocol(val)); + g.fillRect(ttox(time1),y, ttox(time2)-ttox(time1),h); + + if (prevevent.time > t2) reachedend = true; + } + + } +} + + +/** + * This class loads and stores all data entries + * @version 1.0, June 1997 + * @author Fred Howell + */ + +class Entries { + protected List entries; + protected Types types; + + double starttime, endtime; + + Entries() { + entries = new ArrayList(); + types = new Types(); + starttime = 0.0; + endtime = 1.0; + } + + /* External commands */ + void reset() { + entries.clear(); + types.getV().clear(); + starttime = 0.0; + endtime = 1.0; + } + + /** Add a single trace line + * return 1 if successful + */ + final int TYPES = 0; + final int BARS = 1; + final int EVENTS = 2; + int section = TYPES; + int addTrace(String l) { + int success = 1; + if (l.startsWith("$")) { + // System.out.println("Changing section\n"); + if ("$types".compareTo(l) == 0) section = TYPES; + else if ("$bars".compareTo(l) == 0) section = BARS; + else if ("$events".compareTo(l) == 0) section = EVENTS; + else { + System.out.println("Couldn't read section name "+l); + success = 0; + } + } else if (section==TYPES) { + // Format: typename flag1 flag2 ... + types.add(new TypeParam(l)); + } else if (section==BARS) { + // Format: barname bartype + StringTokenizer st = new StringTokenizer(l); + String barname, bartype; + if (st.hasMoreTokens()) { + barname = st.nextToken(); + if (st.hasMoreTokens()) { + bartype = st.nextToken(); + TypeParam btp = types.find(bartype); + if (btp!=null) { + entries.add(new Entry(barname, btp)); + } else { + System.out.println("Couldn't find type "+bartype); + success = 0; + } + } + } + } else if (section==EVENTS) { + StringTokenizer st = new StringTokenizer(l, ": \n\r\t"); + if(st.nextToken().charAt(0) != 'u') + ;//System.out.println("Error: Only do 'u:' traces"); + else { + String barname = st.nextToken(); + Entry e = find(barname); + if (e==null) + ;// System.out.println("Couldn't find bar:"+barname); + else { + st.nextToken(); // skip 'at' + double timestamp = + (Double.valu... [truncated message content] |