datasetdata-analysisanylogicenergy

Fill Datasets with data in a specific time range


I have a simulation that determines the energy requirements of a factory over the period of one year. The energy data of the whole year is in one data set after the simulation went through. Now I want to copy the existing data in a new data set, but only for a specific time period, for example from June 1 to June 31. I use the following code for this:

specificDatasetJune.setCapacity(monthCapacity); //"specificDatasetJune" gets capacity of the time period, e.g. June    
specificDataset.fillFrom(datasetTEST); //Data from fill dataset "datasetTEST" is copied to the "specificDataset".

My problem with my current functions is, that with the function "fillFrom" I cannot specify a time period, because it copies all data from the original data set. If I use this code for example in June, my new dataset gets values from June till December. If I use the code after the finished simulation I only get the data for December. But I want to copy only a specific time window. Is that possible?

I used the following help page from Anylogic:

anylogic.help/api/com/anylogic/engine/analysis/DataSet.html

Best, Christoph


Solution

  • You can (and should) fill the new dataset manually. Simply loop over the original dataset and copy only the bits that you need. Assume the original ds copied data each day, then the x-values are days:

    int startDay = 10; // start Jan 10
    int endDay = 30; // end Jan 30
    ds_Copy.reset(); // delete any old data
    ds_Copy.setCapacity(endDay - startDay); // prepare for new data
    for (int i=0; i<ds_Original.size(); i++) {
        if (i>=startDay && i<endDay) {
            ds_Copy.add(i, ds_Original.getY(i));
        }
    }
    

    Obviously, you can do this at any point in time, be it June or at the end of the model. Just make sure the endDay has actually passed already