Revision 179:786b6f65a623

View differences:

src/main/java/cz/agents/dimaptools/heuristic/landmarks/LMCutHeuristic.java
38 38
        artificialGoal = new Proposition(propositions.size()+1,-1,-1);
39 39
        artificialGoal.isGoal = true;
40 40
        artificialGoal.cost = -1;
41
        goalOperator = new UnaryOperator(operators.size()+1, -1, problem.agent,0);
41
        goalOperator = new UnaryOperator(operators.size()+1, -1, problem.agent,0,false);
42 42
        goalOperator.precondition = new LinkedList<Proposition>();
43 43
        goalOperator.effect = artificialGoal;
44 44
//		artificialGoal.reachedBy = goalOperator;
src/main/java/cz/agents/dimaptools/heuristic/relaxed/RecursiveDistributedRelaxationRequestHeuristic.java
149 149
        if(p.cost == -1 || p.cost > cost){
150 150

  
151 151
            //if operator is owned by other agent (maybe isProjection check should suffice)
152
            if(op != null && !op.agent.equals(problem.agent) && maxRecursionDepth > 0){
152
            if(
153
            		op != null && 			//i.e. initial state
154
            		op.shouldRequest && 	//is projection and not pure
155
            		maxRecursionDepth > 0  	//should send any requests at all
156
            		){
153 157
                if(LOGGER.isDebugEnabled())LOGGER.debug(domain.agent + "("+id+")" + " enqueue public operator: " + problem.getAction(op.actionHash));
154 158

  
155 159
                final RelaxationHeuristicRequest req = new RelaxationHeuristicRequest(agentID, new HeuristicComputedCallback() {
src/main/java/cz/agents/dimaptools/heuristic/relaxed/RelaxationHeuristic.java
113 113
				}
114 114
				for(int var = 0; var < domain.sizeGlobal(); ++var){
115 115
					if(a.getEffect().isSet(var) && domain.isPublicVar(var) && domain.isPublicVal(a.getEffect().getValue(var))){
116
						UnaryOperator op = new UnaryOperator(operators.size(),a.hashCode(),a.getOwner());
117
						op.precondition = pre;
118
						op.effect = propositions.get(var).get(a.getEffect().getValue(var));
119
						operators.add(op);
120

  
121
						if(LOGGER.isDebugEnabled())LOGGER.debug(domain.agent + " added"+(a.isPublic()?" public":"")+" operator " + a.getLabel() + "("+var+"-"+a.getEffect().getValue(var)+"):"+op.operatorsIndex);
116
						buildOperator(pre, var, a);
122 117
					}
123 118
				}
124 119
			}
......
136 131
						if(domain.isPublicVar(var) && domain.isPublicVal(a.getEffect().getValue(var))){
137 132
							continue;
138 133
						}
139
						UnaryOperator op = new UnaryOperator(operators.size(),a.hashCode(),a.getOwner());
140
						op.precondition = pre;
141
						op.effect = propositions.get(var).get(a.getEffect().getValue(var));
142
						operators.add(op);
143

  
144
						if(LOGGER.isDebugEnabled())LOGGER.debug(domain.agent + " added"+(a.isPublic()?" public":"")+" operator " + a.getLabel() + "("+var+"-"+a.getEffect().getValue(var)+"):"+op.operatorsIndex);
134
						buildOperator(pre, var, a);
145 135
					}
146 136
				}
147 137
			}
......
156 146
				}
157 147
				for(int var = 0; var < domain.sizeGlobal(); ++var){
158 148
					if(a.getEffect().isSet(var)){
159
						UnaryOperator op = new UnaryOperator(operators.size(),a.hashCode(),a.getOwner());
160
						op.precondition = pre;
161
						op.effect = propositions.get(var).get(a.getEffect().getValue(var));
162
						operators.add(op);
163

  
164
						if(LOGGER.isDebugEnabled())LOGGER.debug(domain.agent + " added"+(a.isPublic()?" public":"")+" operator " + a.getLabel() + "("+var+"-"+a.getEffect().getValue(var)+"):"+op.operatorsIndex);
149
						buildOperator(pre, var, a);
165 150
					}
166 151
				}
167 152
			}
......
179 164
		 initialized = true;
180 165

  
181 166
	}
167
	
168
	private void buildOperator(List<Proposition> pre, int var, Action a){
169
		UnaryOperator op = new UnaryOperator(operators.size(),a.hashCode(),a.getOwner(),a.getCost(),a.isProjection() && !a.isPure());
170
		op.precondition = pre;
171
		op.effect = propositions.get(var).get(a.getEffect().getValue(var));
172
		operators.add(op);
173
		if(LOGGER.isDebugEnabled())LOGGER.debug(domain.agent + " added"+(a.isPublic()?" public":"")+" operator " + a.getLabel() + "("+var+"-"+a.getEffect().getValue(var)+"):"+op.operatorsIndex);
174
	}
182 175

  
183 176
	public void buildGoalPropositions(SuperState goal){
184 177
		if(LOGGER.isDebugEnabled())LOGGER.debug(domain.agent + " build goal propositions: " + Arrays.toString(goal.getValues()) + ":" + domain.humanize(goal.getValues()));
src/main/java/cz/agents/dimaptools/heuristic/relaxed/UnaryOperator.java
12 12
    public int cost = -1;
13 13

  
14 14
    String agent;
15
    
16
    public final boolean shouldRequest;
15 17

  
16 18
    public List<Proposition> precondition;
17 19
    public Proposition effect;
......
20 22
    public Proposition hMaxSupporter;
21 23

  
22 24

  
23
    public UnaryOperator(int operatorNo, int actionHash, String agent, int baseCost) {
25
    public UnaryOperator(int operatorNo, int actionHash, String agent, int baseCost, boolean shouldRequest) {
24 26
        super();
25 27
        this.operatorsIndex = operatorNo;
26 28
        this.actionHash = actionHash;
27 29
        this.agent = agent;
28 30
        this.baseCost = baseCost;
31
        this.shouldRequest = shouldRequest;
29 32
    }
30 33

  
31
    public UnaryOperator(int operatorNo, int actionHash, String agent) {
32
        super();
33
        this.operatorsIndex = operatorNo;
34
        this.actionHash = actionHash;
35
        this.agent = agent;
36
        this.baseCost = 1;
34
    public UnaryOperator(int operatorNo, int actionHash, String agent, boolean shouldRequest) {
35
        this(operatorNo, actionHash, agent,1,shouldRequest);
37 36
    }
38 37

  
39 38
    public void setHMaxSupporter(Proposition supporter, int cost){
src/main/java/cz/agents/dimaptools/input/sas/SASPreprocessor.java
412 412
			if (!otherAgent.equals(agent)) {
413 413
				for (SASOperator op : agentOperators.get(otherAgent)) {
414 414
					if (op.isPublic) {
415
						boolean isNotPure = false;
416
						
415 417
						SuperState pre = new SuperState(d);
416 418
						for (String var : op.pre.keySet()) {
417
							pre.forceSetValue(varCodes.get(var), valCodes.get(op.pre.get(var)));
419
							isNotPure = isNotPure || pre.forceSetValue(varCodes.get(var), valCodes.get(op.pre.get(var)));
418 420
						}
419 421

  
420 422
						SuperState eff = new SuperState(d);
......
422 424
							eff.forceSetValue(varCodes.get(var), valCodes.get(op.eff.get(var)));
423 425
						}
424 426

  
425
						Action a = new Action(op.label, otherAgent, pre, eff, true, true);
427
						Action a = new Action(op.label, otherAgent, pre, eff, true, true, !isNotPure);
426 428
						allActions.add(a);
427 429
						if(a.isPublic()){
428 430
							publicActions.add(a);
src/main/java/cz/agents/dimaptools/model/Action.java
12 12

  
13 13
    private final boolean isPublic;
14 14
    private final boolean isProjection;
15
    private final boolean isPure;
15 16

  
16 17
    private final int hash;
17 18

  
18 19
    public Action(String label, String agentName, SuperState precondition, SuperState effect, boolean isPublic) {
19 20
    	this(label, agentName, precondition, effect, isPublic, false);
20 21
    }
22
    
23
    public Action(String label, String agentName, SuperState precondition, SuperState effect, boolean isPublic, boolean isProjection) {
24
    	this(label, agentName, precondition, effect, isPublic,isProjection, false);
25
    }
21 26

  
22
    public Action(String label, String agentName, SuperState precondition, SuperState effect, boolean isPublic, boolean isProjection) {
27
    public Action(String label, String agentName, SuperState precondition, SuperState effect, boolean isPublic, boolean isProjection, boolean isPure) {
23 28
        this.label = label;
24 29
        this.agentOwner = agentName;
25 30
        this.precondition = precondition;
26 31
        this.effect = effect;
27 32
        this.isPublic = isPublic;
28 33
        this.isProjection = isProjection;
34
        this.isPure = isPure;
29 35

  
30 36
        String agentAndLabel = agentName + ": " + label;
31 37
		hash = agentAndLabel.hashCode();
......
48 54
    }
49 55

  
50 56
    public String getLabel() {
51
        return isProjection ? "*"+label+"("+agentOwner+")" : label;
57
        return isProjection ? "*"+label+"("+agentOwner+")[" + isPure + "]" : label;
52 58
    }
53 59

  
54 60
    /**
......
70 76
    public boolean isProjection() {
71 77
        return isProjection;
72 78
    }
79
    
80
    /**
81
     * TRUE if action is a projection, but the original action had no private preconditions
82
     * @return
83
     */
84
    public boolean isPure() {
85
        return isProjection && isPure;
86
    }
73 87

  
74 88
    public SuperState getEffect(){
75 89
        return effect;
......
128 142
		return 2 + 4 + 4 + precondition.getBytes() + effect.getBytes();
129 143
	}
130 144

  
145
	public int getCost() {
146
		return 1;
147
	}
148

  
131 149

  
132 150

  
133 151

  
src/main/java/cz/agents/dimaptools/model/Problem.java
74 74
	public Set<Action> getProjectedActions() {
75 75
		return projectedActions;
76 76
	}
77
	
78
	/**
79
	 * Get all pure projections of public actions owned by other agents.
80
	 * @return
81
	 */
82
	public Set<Action> getPureProjectedActions() {
83
		Set<Action> ppa = new HashSet<Action>();
84
		for(Action a : projectedActions){
85
			if(a.isPure())ppa.add(a);
86
		}
87
		return ppa;
88
	}
77 89

  
78 90
	/**
79 91
	 * Get all public actions and projections
src/main/java/cz/agents/dimaptools/model/SuperState.java
116 116
	 * Set value without (WARNING) consistency checks
117 117
	 * @param var
118 118
	 * @param val
119
	 * @return returns true if setting was forced, i.e either the set variable or value are not in the agent's domain
119 120
	 */
120
	public void forceSetValue(int var, int val) {
121
	public boolean forceSetValue(int var, int val) {
121 122
		if(!domain.isDefined(values[var]) && domain.isDefined(val)){
122 123
        	++setValues;
123 124
        }
124 125
        values[var] = val;
125 126
        hash = 0;
127
        
128
        return !domain.inDomainVar(var) || !domain.inDomainVal(val);
126 129
    }
127 130

  
128 131
	public void setAllValuesBy(SuperState superState) {
......
168 171
//        LOGGER.info("TRUE");
169 172
        return true;
170 173
    }
171

  
174
	
172 175

  
173 176
	public boolean equals(Object obj) {
174 177
        if (obj instanceof SuperState) {

Also available in: Unified diff