Package de.timefinder.algo.constraint

Source Code of de.timefinder.algo.constraint.RasterConstraint

/*
*  Copyright 2009 Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net.
*
*  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.
*  under the License.
*/
package de.timefinder.algo.constraint;

import de.timefinder.data.Event;
import de.timefinder.data.algo.Assignment;
import de.timefinder.data.algo.Constraint;
import de.timefinder.data.set.BitRaster;
import de.timefinder.data.set.WeekRaster;

/**
* @author Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net
*/
public class RasterConstraint extends Constraint {

    private static final long serialVersionUID = 4517051950429717349L;
    private WeekRaster raster;

    private RasterConstraint() {
    }

    public RasterConstraint(WeekRaster raster) {
        this.raster = raster;
    }

    public WeekRaster getRaster() {
        return raster;
    }

    public void setRaster(WeekRaster raster) {
        this.raster = raster;
    }

    @Override
    public int getViolations(Object obj) {
        Assignment ass = (Assignment) obj;
        if (ass.getStart() < 0)
            return 0;

        int counter = 0;
        Event ev = ass.getEvent();
        BitRaster refRaster = getRaster().getForbidden();
        int end = ass.getStart() + ev.getDuration();
        for (int i = ass.getStart(); i < end; i++) {
            if (refRaster.isAssigned(i))
                counter++;
        }
        return counter;
    }
}
TOP

Related Classes of de.timefinder.algo.constraint.RasterConstraint

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.