aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/VIATRA-Solver/org.eclipse.viatra.dse/src/org/eclipse/viatra/dse/objectives/impl/DepthHardObjective.java
blob: b21da3970db0bb563dda1139c788f846e5815252 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*******************************************************************************
 * Copyright (c) 2010-2016, Andras Szabolcs Nagy, Zoltan Ujhelyi and Daniel Varro
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-v20.html.
 * 
 * SPDX-License-Identifier: EPL-2.0
 *******************************************************************************/
package org.eclipse.viatra.dse.objectives.impl;

import org.eclipse.viatra.dse.base.ThreadContext;
import org.eclipse.viatra.dse.objectives.IObjective;

/**
 * This hard objective is fulfilled if the trajectory is in the specified interval (inclusive).
 * 
 * @author Andras Szabolcs Nagy
 *
 */
public class DepthHardObjective extends BaseObjective {

    private static final String DEFAULT_NAME = "DepthHardObjective";
    protected int minDepth;
    protected int maxDepth;
    private ThreadContext context;

    public DepthHardObjective() {
        this(DEFAULT_NAME, 0, Integer.MAX_VALUE);
    }

    public DepthHardObjective(String name) {
        this(name, 0, Integer.MAX_VALUE);
    }

    public DepthHardObjective(int minDepth) {
        this(DEFAULT_NAME, minDepth, Integer.MAX_VALUE);
    }

    public DepthHardObjective(String name, int minDepth) {
        this(name, minDepth, Integer.MAX_VALUE);
    }

    public DepthHardObjective(int minDepth, int maxDepth) {
        this(DEFAULT_NAME, minDepth, maxDepth);
    }
    
    public DepthHardObjective(String name, int minDepth, int maxDepth) {
        super(name);
        this.minDepth = minDepth;
        this.maxDepth = maxDepth;
    }

    public DepthHardObjective withMinDepth(int minDepth) {
        this.minDepth = minDepth;
        return this;
    }

    public DepthHardObjective withMaxDepth(int maxDepth) {
        this.maxDepth = maxDepth;
        return this;
    }

    @Override
    public void init(ThreadContext context) {
        super.init(context);
        this.context = context;
    }

    @Override
    public Double getFitness(ThreadContext context) {
        return 0d;
    }

    @Override
    public boolean isHardObjective() {
        return true;
    }

    @Override
    public boolean satisifiesHardObjective(Double fitness) {
        return minDepth <= context.getDepth() && context.getDepth() <= maxDepth;
    }

    @Override
    public IObjective createNew() {
        return new DepthHardObjective(name, minDepth, maxDepth);
    }

}