Advertisement
MatexN

Untitled

Jan 22nd, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.10 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.IOException;
  3. import java.math.BigDecimal;
  4. import java.util.LinkedList;
  5. import java.util.Properties;
  6. import java.util.Scanner;
  7. import java.util.logging.FileHandler;
  8. import java.util.logging.Logger;
  9. import java.util.logging.SimpleFormatter;
  10.  
  11. import dissimlab.monitors.Diagram;
  12. import dissimlab.monitors.Diagram.DiagramType;
  13. import dissimlab.monitors.MonitoredVar;
  14. import dissimlab.monitors.Statistics;
  15. import dissimlab.simcore.SimControlException;
  16. import dissimlab.simcore.SimManager;
  17.  
  18. public class Application {
  19.  
  20.     public static Properties properties;
  21.  
  22.     public static int NumberOfCashiers;
  23.     public static int MaxClients;
  24.     public static int AppearMin = Integer.parseInt(properties.getProperty("AppearMin"));
  25.     public static int AppearMax = Integer.parseInt(properties.getProperty("AppearMax"));
  26.     public static int StartServiceMin = Integer.parseInt(properties.getProperty("StartServiceMin"));
  27.     public static int StartServiceMax = Integer.parseInt(properties.getProperty("StartServiceMax"));
  28.     public static int EndServiceMin = Integer.parseInt(properties.getProperty("EndServiceMin"));
  29.     public static int EndServiceMax = Integer.parseInt(properties.getProperty("EndServiceMax"));
  30.     public static int ImpatintMin = Integer.parseInt(properties.getProperty("ImpatintMin"));
  31.     public static int ImpatientMax = Integer.parseInt(properties.getProperty("ImpatientMax"));
  32.     public static int RepairMin = Integer.parseInt(properties.getProperty("RepairMin"));
  33.     public static int RepairMax = Integer.parseInt(properties.getProperty("RepairMax"));
  34.  
  35.     public static MonitoredVar mvServicingTime = new MonitoredVar();
  36.     public static MonitoredVar mvNumberOfClients = new MonitoredVar();
  37.     public static MonitoredVar mvResignation = new MonitoredVar();
  38.     public static MonitoredVar mvWaitingTime = new MonitoredVar();
  39.  
  40.     public static final Logger LOGGER = Logger.getLogger(Application.class.getName());
  41.  
  42.     public static void main(String[] args) throws SimControlException, IOException {
  43.  
  44.         Properties properties = new Properties();
  45.         properties.load(Application.class.getClassLoader().getResourceAsStream("settings.properties"));
  46.  
  47.        
  48.         File file = new File("C:/Users/MatexN/Desktop/PSY_PROJEKT/log/simlog.log");
  49.         file.createNewFile();
  50.         FileHandler fh = new FileHandler(file.getPath());
  51.         LOGGER.addHandler(fh);
  52.         SimpleFormatter formatter = new SimpleFormatter();
  53.         fh.setFormatter(formatter);
  54.         LOGGER.setUseParentHandlers(false);
  55.         LOGGER.info("Poczatek symulacji");
  56.  
  57.         System.out.println("Number of Cashiers: ");
  58.         Scanner sc = new Scanner(System.in);
  59.         Application.NumberOfCashiers = sc.nextInt();
  60.         System.out.println("Max number of clients: ");
  61.         Application.MaxClients = sc.nextInt();
  62.         LOGGER.info("Number of Cashiers: " + String.valueOf(NumberOfCashiers));
  63.         LOGGER.info("Max number of clients: " + String.valueOf(MaxClients));
  64.         Bank scene = Bank.getInstance(Application.generateCashiers(Application.NumberOfCashiers));
  65.         new CustomerAppearEvent(scene, scene.getGen().uniform(Application.AppearMin, Application.AppearMax));
  66.  
  67.         SimManager mgr = SimManager.getInstance();
  68.         mgr.startSimulation();
  69.  
  70.         double wynik = new BigDecimal(Statistics.arithmeticMean(Application.mvServicingTime)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  71.         LOGGER.info("Oczekiwany graniczny czas obsługi klienta:   " + wynik);
  72.  
  73.         wynik = new BigDecimal(Statistics.arithmeticMean(Application.mvNumberOfClients)).setScale(2, BigDecimal.ROUND_HALF_UP).intValue();
  74.         LOGGER.info("Oczekiwana graniczna liczba klientow w kolejce:   " + wynik);
  75.  
  76.         wynik = new BigDecimal(Statistics.arithmeticMean(Application.mvResignation)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  77.         LOGGER.info("Prawdopodobienstwo rezygnacji z obslugi   " + wynik);
  78.  
  79.         wynik = new BigDecimal(Statistics.arithmeticMean(Application.mvWaitingTime)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  80.         LOGGER.info("Oczekiwany graniczny czas oczekiwania w kolejce   " + wynik);
  81.  
  82.  
  83.         Diagram d3 = new Diagram(DiagramType.HISTOGRAM, "Oczekiwany graniczny czas obsługi klienta:");
  84.         d3.add(Application.mvServicingTime, java.awt.Color.BLUE);
  85.         d3.show();
  86.  
  87.         Diagram d = new Diagram(DiagramType.DISTRIBUTION, "Prawdopodobienstwo rezygnacji z obslugi");
  88.         d.add(Application.mvResignation, java.awt.Color.RED);
  89.         d.show();
  90.  
  91.         Diagram d1 = new Diagram(DiagramType.HISTOGRAM, "Oczekiwany graniczny czas oczekiwania w kolejce");
  92.         d1.add(mvWaitingTime, java.awt.Color.GREEN);
  93.         d1.show();
  94.         System.out.println("SimModel: Simulation finished");
  95.         LOGGER.info("Koniec symulacji");
  96.     }
  97.  
  98.     public static LinkedList<Cashier> generateCashiers(int l) {
  99.         LinkedList<Cashier> tmp = new LinkedList<>();
  100.         for (int i = 1; i <= l; i++) {
  101.             Cashier c = new Cashier(i);
  102.             tmp.add(c);
  103.         }
  104.         return tmp;
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement