<commit_before>/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2002-2011 Ausenco Engineering Canada Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
package com.sandwell.JavaSimulation3D;

import static com.sandwell.JavaSimulation.Util.formatNumber;

import java.util.ArrayList;
import java.util.HashMap;

import com.jaamsim.input.InputAgent;
import com.jaamsim.math.Color4d;
import com.sandwell.JavaSimulation.BooleanInput;
import com.sandwell.JavaSimulation.BooleanListInput;
import com.sandwell.JavaSimulation.BooleanVector;
import com.sandwell.JavaSimulation.ColourInput;
import com.sandwell.JavaSimulation.DoubleInput;
import com.sandwell.JavaSimulation.DoubleListInput;
import com.sandwell.JavaSimulation.DoubleVector;
import com.sandwell.JavaSimulation.EntityInput;
import com.sandwell.JavaSimulation.EntityListInput;
import com.sandwell.JavaSimulation.ErrorException;
import com.sandwell.JavaSimulation.FileEntity;
import com.sandwell.JavaSimulation.Input;
import com.sandwell.JavaSimulation.InputErrorException;
import com.sandwell.JavaSimulation.IntegerVector;
import com.sandwell.JavaSimulation.Keyword;
import com.sandwell.JavaSimulation.ProbabilityDistribution;
import com.sandwell.JavaSimulation.Process;
import com.sandwell.JavaSimulation.Tester;
import com.sandwell.JavaSimulation.Vector;

/**
 * Class ModelEntity - JavaSimulation3D
 */
public class ModelEntity extends DisplayEntity {

	// Breakdowns

	@Keyword(desc = "Reliability is defined as:\n" +
	                " 100% - (plant breakdown time / total operation time)\n " +
	                "or\n " +
	                "(Operational Time)/(Breakdown + Operational Time)",
	         example = "Object1 Reliability { 0.95 }")
	private final DoubleInput availability;
	protected double hoursForNextFailure;    // The number of working hours required before the next breakdown
	protected double iATFailure;             // inter arrival time between failures
	protected boolean breakdownPending;          // true when a breakdown is to occur
	protected boolean brokendown;                // true => entity is presently broken down
	protected boolean maintenance;               // true => entity is presently in maintenance
	protected boolean associatedBreakdown;       // true => entity is presently in Associated Breakdown
	protected boolean associatedMaintenance;     // true => entity is presently in Associated Maintenance
	protected double breakdownStartTime;         // Start time of the most recent breakdown
	protected double breakdownEndTime;           // End time of the most recent breakdown

	// Breakdown Probability Distributions
	@Keyword(desc = "A ProbabilityDistribution object that governs the duration of breakdowns (in hours).",
	         example = "Object1  DowntimeDurationDistribution { BreakdownProbDist1 }")
	private final EntityInput<ProbabilityDistribution> downtimeDurationDistribution;

	@Keyword(desc = "A ProbabilityDistribution object that governs when breakdowns occur (in hours).",
	         example = "Object1  DowntimeIATDistribution { BreakdownProbDist1 }")
	private final EntityInput<ProbabilityDistribution> downtimeIATDistribution;

	// Maintenance

	@Keyword(desc = "The simulation time for the start of the first maintenance for each maintenance cycle.",
	         example = "Object1 FirstMaintenanceTime { 24 h }")
	protected DoubleListInput firstMaintenanceTimes;

	@Keyword(desc = "The time between maintenance activities for each maintenance cycle",
	         example = "Object1 MaintenanceInterval { 168 h }")
	protected DoubleListInput maintenanceIntervals;

	@Keyword(desc = "The durations of a single maintenance event for each maintenance cycle.",
	         example = "Object1 MaintenanceDuration { 336 h }")
	protected DoubleListInput maintenanceDurations;
	protected IntegerVector maintenancePendings;  // Number of maintenance periods that are due

	@Keyword(desc = "A Boolean value. Allows scheduled maintenances to be skipped if it overlaps " +
	                "with another planned maintenance event.",
	         example = "Object1 SkipMaintenanceIfOverlap { TRUE }")
	protected BooleanListInput skipMaintenanceIfOverlap;

	@Keyword(desc = "A list of objects that share the maintenance schedule with this object. " +
	                "In order for the maintenance to start, all objects on this list must be available." +
	                "This keyword is for Handlers and Signal Blocks only.",
	         example = "Block1 SharedMaintenance { Block2 Block2 }")
	private final EntityListInput<ModelEntity> sharedMaintenanceList;
	protected ModelEntity masterMaintenanceEntity;  // The entity that has maintenance information

	protected boolean performMaintenanceAfterShipDelayPending;			// maintenance needs to be done after shipDelay

	// Maintenance based on hours of operations

	@Keyword(desc = "Working time for the start of the first maintenance for each maintenance cycle",
	         example = "Object1 FirstMaintenanceOperatingHours { 1000 2500 h }")
	private final DoubleListInput firstMaintenanceOperatingHours;

	@Keyword(desc = "Working time between one maintenance event and the next for each maintenance cycle",
	         example = "Object1 MaintenanceOperatingHoursIntervals { 2000 5000 h }")
	private final DoubleListInput maintenanceOperatingHoursIntervals;

	@Keyword(desc = "Duration of maintenance events based on working hours for each maintenance cycle",
	         example = "Ship1 MaintenanceOperatingHoursDurations { 24 48 h }")
	private final DoubleListInput maintenanceOperatingHoursDurations;
	protected IntegerVector maintenanceOperatingHoursPendings;  // Number of maintenance periods that are due
	protected DoubleVector hoursForNextMaintenanceOperatingHours;

	protected double maintenanceStartTime; // Start time of the most recent maintenance
	protected double maintenanceEndTime; // End time of the most recent maintenance
	protected DoubleVector nextMaintenanceTimes; // next start time for each maintenance
	protected double nextMaintenanceDuration; // duration for next maintenance
	protected DoubleVector lastScheduledMaintenanceTimes;

	@Keyword(desc = "If maintenance has been deferred by the DeferMaintenanceLookAhead keyword " +
	                "for longer than this time, the maintenance will start even if " +
	                "there is an object within the lookahead. There must be one entry for each " +
	                "defined maintenance schedule if DeferMaintenanceLookAhead is used.  This" +
	                "keyword is only used for signal blocks.",
	         example = "Object1 DeferMaintenanceLimit { 50 50 h }")
	private final DoubleListInput deferMaintenanceLimit;


	@Keyword(desc = "If the duration of the downtime is longer than this time, equipment will be released",
	         example = "Object1 DowntimeToReleaseEquipment { 1.0 h }")
	protected final DoubleInput downtimeToReleaseEquipment;

	@Keyword(desc = "A list of Boolean values corresponding to the maintenance cycles. If a value is TRUE, " +
	                "then routes/tasks are released before performing the maintenance in the cycle.",
	         example = "Object1 ReleaseEquipment { TRUE FALSE FALSE }")
	protected final BooleanListInput releaseEquipment;

	@Keyword(desc = "A list of Boolean values corresponding to the maintenance cycles. If a value is " +
	                "TRUE, then maintenance in the cycle can start even if the equipment is presently " +
	                "working.",
	         example = "Object1 ForceMaintenance { TRUE FALSE FALSE }")
	protected final BooleanListInput forceMaintenance;

	// Statistics

	@Keyword(desc = "If TRUE, then statistics for this object are " +
	                "included in the main output report.",
	         example = "Object1 PrintToReport { TRUE }")
	private final BooleanInput printToReport;

	// States
	protected static Vector stateList = new Vector( 11, 1 ); // List of valid states
	private final HashMap<String, StateRecord> stateMap;
	protected double workingHours;                    // Accumulated working time spent in working states

private static class StateRecord {
	String stateName;
	int index;
	double initializationHours;<commit_msg>JS: make ModelEntity stateList private<commit_after>/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2002-2011 Ausenco Engineering Canada Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
package com.sandwell.JavaSimulation3D;

import static com.sandwell.JavaSimulation.Util.formatNumber;

import java.util.ArrayList;
import java.util.HashMap;

import com.jaamsim.input.InputAgent;
import com.jaamsim.math.Color4d;
import com.sandwell.JavaSimulation.BooleanInput;
import com.sandwell.JavaSimulation.BooleanListInput;
import com.sandwell.JavaSimulation.BooleanVector;
import com.sandwell.JavaSimulation.ColourInput;
import com.sandwell.JavaSimulation.DoubleInput;
import com.sandwell.JavaSimulation.DoubleListInput;
import com.sandwell.JavaSimulation.DoubleVector;
import com.sandwell.JavaSimulation.EntityInput;
import com.sandwell.JavaSimulation.EntityListInput;
import com.sandwell.JavaSimulation.ErrorException;
import com.sandwell.JavaSimulation.FileEntity;
import com.sandwell.JavaSimulation.Input;
import com.sandwell.JavaSimulation.InputErrorException;
import com.sandwell.JavaSimulation.IntegerVector;
import com.sandwell.JavaSimulation.Keyword;
import com.sandwell.JavaSimulation.ProbabilityDistribution;
import com.sandwell.JavaSimulation.Process;
import com.sandwell.JavaSimulation.Tester;
import com.sandwell.JavaSimulation.Vector;

/**
 * Class ModelEntity - JavaSimulation3D
 */
public class ModelEntity extends DisplayEntity {

	// Breakdowns

	@Keyword(desc = "Reliability is defined as:\n" +
	                " 100% - (plant breakdown time / total operation time)\n " +
	                "or\n " +
	                "(Operational Time)/(Breakdown + Operational Time)",
	         example = "Object1 Reliability { 0.95 }")
	private final DoubleInput availability;
	protected double hoursForNextFailure;    // The number of working hours required before the next breakdown
	protected double iATFailure;             // inter arrival time between failures
	protected boolean breakdownPending;          // true when a breakdown is to occur
	protected boolean brokendown;                // true => entity is presently broken down
	protected boolean maintenance;               // true => entity is presently in maintenance
	protected boolean associatedBreakdown;       // true => entity is presently in Associated Breakdown
	protected boolean associatedMaintenance;     // true => entity is presently in Associated Maintenance
	protected double breakdownStartTime;         // Start time of the most recent breakdown
	protected double breakdownEndTime;           // End time of the most recent breakdown

	// Breakdown Probability Distributions
	@Keyword(desc = "A ProbabilityDistribution object that governs the duration of breakdowns (in hours).",
	         example = "Object1  DowntimeDurationDistribution { BreakdownProbDist1 }")
	private final EntityInput<ProbabilityDistribution> downtimeDurationDistribution;

	@Keyword(desc = "A ProbabilityDistribution object that governs when breakdowns occur (in hours).",
	         example = "Object1  DowntimeIATDistribution { BreakdownProbDist1 }")
	private final EntityInput<ProbabilityDistribution> downtimeIATDistribution;

	// Maintenance

	@Keyword(desc = "The simulation time for the start of the first maintenance for each maintenance cycle.",
	         example = "Object1 FirstMaintenanceTime { 24 h }")
	protected DoubleListInput firstMaintenanceTimes;

	@Keyword(desc = "The time between maintenance activities for each maintenance cycle",
	         example = "Object1 MaintenanceInterval { 168 h }")
	protected DoubleListInput maintenanceIntervals;

	@Keyword(desc = "The durations of a single maintenance event for each maintenance cycle.",
	         example = "Object1 MaintenanceDuration { 336 h }")
	protected DoubleListInput maintenanceDurations;
	protected IntegerVector maintenancePendings;  // Number of maintenance periods that are due

	@Keyword(desc = "A Boolean value. Allows scheduled maintenances to be skipped if it overlaps " +
	                "with another planned maintenance event.",
	         example = "Object1 SkipMaintenanceIfOverlap { TRUE }")
	protected BooleanListInput skipMaintenanceIfOverlap;

	@Keyword(desc = "A list of objects that share the maintenance schedule with this object. " +
	                "In order for the maintenance to start, all objects on this list must be available." +
	                "This keyword is for Handlers and Signal Blocks only.",
	         example = "Block1 SharedMaintenance { Block2 Block2 }")
	private final EntityListInput<ModelEntity> sharedMaintenanceList;
	protected ModelEntity masterMaintenanceEntity;  // The entity that has maintenance information

	protected boolean performMaintenanceAfterShipDelayPending;			// maintenance needs to be done after shipDelay

	// Maintenance based on hours of operations

	@Keyword(desc = "Working time for the start of the first maintenance for each maintenance cycle",
	         example = "Object1 FirstMaintenanceOperatingHours { 1000 2500 h }")
	private final DoubleListInput firstMaintenanceOperatingHours;

	@Keyword(desc = "Working time between one maintenance event and the next for each maintenance cycle",
	         example = "Object1 MaintenanceOperatingHoursIntervals { 2000 5000 h }")
	private final DoubleListInput maintenanceOperatingHoursIntervals;

	@Keyword(desc = "Duration of maintenance events based on working hours for each maintenance cycle",
	         example = "Ship1 MaintenanceOperatingHoursDurations { 24 48 h }")
	private final DoubleListInput maintenanceOperatingHoursDurations;
	protected IntegerVector maintenanceOperatingHoursPendings;  // Number of maintenance periods that are due
	protected DoubleVector hoursForNextMaintenanceOperatingHours;

	protected double maintenanceStartTime; // Start time of the most recent maintenance
	protected double maintenanceEndTime; // End time of the most recent maintenance
	protected DoubleVector nextMaintenanceTimes; // next start time for each maintenance
	protected double nextMaintenanceDuration; // duration for next maintenance
	protected DoubleVector lastScheduledMaintenanceTimes;

	@Keyword(desc = "If maintenance has been deferred by the DeferMaintenanceLookAhead keyword " +
	                "for longer than this time, the maintenance will start even if " +
	                "there is an object within the lookahead. There must be one entry for each " +
	                "defined maintenance schedule if DeferMaintenanceLookAhead is used.  This" +
	                "keyword is only used for signal blocks.",
	         example = "Object1 DeferMaintenanceLimit { 50 50 h }")
	private final DoubleListInput deferMaintenanceLimit;


	@Keyword(desc = "If the duration of the downtime is longer than this time, equipment will be released",
	         example = "Object1 DowntimeToReleaseEquipment { 1.0 h }")
	protected final DoubleInput downtimeToReleaseEquipment;

	@Keyword(desc = "A list of Boolean values corresponding to the maintenance cycles. If a value is TRUE, " +
	                "then routes/tasks are released before performing the maintenance in the cycle.",
	         example = "Object1 ReleaseEquipment { TRUE FALSE FALSE }")
	protected final BooleanListInput releaseEquipment;

	@Keyword(desc = "A list of Boolean values corresponding to the maintenance cycles. If a value is " +
	                "TRUE, then maintenance in the cycle can start even if the equipment is presently " +
	                "working.",
	         example = "Object1 ForceMaintenance { TRUE FALSE FALSE }")
	protected final BooleanListInput forceMaintenance;

	// Statistics

	@Keyword(desc = "If TRUE, then statistics for this object are " +
	                "included in the main output report.",
	         example = "Object1 PrintToReport { TRUE }")
	private final BooleanInput printToReport;

	// States
	private static Vector stateList = new Vector( 11, 1 ); // List of valid states
	private final HashMap<String, StateRecord> stateMap;
	protected double workingHours;                    // Accumulated working time spent in working states

private static class StateRecord {
	String stateName;
	int index;
	double initializationHours;
{'fraction_non_alphanumeric': 0.061592736105488405, 'fraction_numerical': 0.008675033254294142, 'mean_word_length': 3.9675380637747772, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '372550', 'n_tokens_mistral': 4424, 'n_tokens_neox': 4080, 'n_words': 1647}