/*
 * Source code of the experiments from our 2015 paper 
 * "Utility-driven anonymization of high-dimensional data"
 *      
 * Copyright (C) 2015 Fabian Prasser, Raffael Bild, Johanna Eicher, Helmut Spengler, Florian Kohlmayer
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.deidentifier.arx.algorithm;

import org.deidentifier.arx.framework.check.NodeChecker;
import org.deidentifier.arx.framework.lattice.SolutionSpace;
import org.deidentifier.arx.framework.lattice.Transformation;

import cern.colt.list.DoubleArrayList;

/**
 * Abstract base class
 * 
 * @author Fabian Prasser
 */
public abstract class BenchmarkAlgorithm extends AbstractAlgorithm {

    /** Start time of the search process */
    private long            time        = 0;

    /** Time at which the optimum was discovered */
    private int             discovery   = 0;

    /** The track record */
    private DoubleArrayList trackRecord = new DoubleArrayList();

    /** Optimal utility */
    private double          lastUtility     = 0d;

    /**
     * Creates a new instance
     * @param arg0
     * @param arg1
     */
    protected BenchmarkAlgorithm(SolutionSpace arg0, NodeChecker arg1) {
        super(arg0, arg1);
    }

    /**
     * Returns the time at which the optimum was discovered
     * @return
     */
    public int getDiscoveryTime() {
        return discovery;
    }

    /**
     * Returns a track record of the previous run. List containing tuples <time, utility>.
     * @return
     */
    public DoubleArrayList getTrackRecord() {
        return this.trackRecord;
    }

    @Override
    public void traverse() {
        this.time = System.currentTimeMillis();
        this.search();
    }
    
    /**
     * Search method
     */
    protected abstract void search();
    
    @Override
    protected void trackOptimum(Transformation arg0) {

        long previousId = getGlobalOptimum() == null ? -1 : getGlobalOptimum().getIdentifier();
        super.trackOptimum(arg0);
        long newId = getGlobalOptimum() == null ? -1 : getGlobalOptimum().getIdentifier();
        if ((this instanceof AlgorithmLightning) && previousId != newId) {
            double utility = Double.valueOf(getGlobalOptimum().getInformationLoss().toString());
            if (utility != this.lastUtility) {
                int localdiscovery = (int)(System.currentTimeMillis() - time);
                // Sometimes, there seem to be problems with milliseconds resolution
                if (localdiscovery == discovery) { 
                    localdiscovery++;
                }
                this.discovery = localdiscovery;
                this.trackRecord.add(this.discovery);
                this.trackRecord.add(utility);
                this.lastUtility = utility;
            }
        }
    }
}

@@ -1506,89 +1506,8 @@
 %0D%0A%0D%0A
-    /** Optimal utility */%0D%0A    private double          lastUtility     = 0d;%0D%0A%0D%0A
     
@@ -2789,69 +2789,13 @@
     
-if (utility != this.lastUtility) %7B%0D%0A                int local
+this.
 disc
@@ -2807,16 +2807,17 @@
  = (int)
+ 
 (System.
@@ -2850,259 +2850,8 @@
 );%0D%0A
-                // Sometimes, there seem to be problems with milliseconds resolution%0D%0A                if (localdiscovery == discovery) %7B %0D%0A                    localdiscovery++;%0D%0A                %7D%0D%0A                this.discovery = localdiscovery;%0D%0A    
     
@@ -2901,36 +2901,32 @@
 );%0D%0A            
-    
 this.trackRecord
@@ -2945,68 +2945,8 @@
 );%0D%0A
-                this.lastUtility = utility;%0D%0A            %7D%0D%0A
     

Simplify code