Revision 343:131532fe9ff4

View differences:

src/main/java/cz/agents/dimaptools/costpart/AbstractionLPOCPGenerator.java
47 47
		MergeAndShrink mas = new MergeAndShrink(prob,stateLimit);
48 48
		mas.mergeAndShrink(ShrinkStrategy.EQUAL_G);
49 49
		
50
		
51
		stateConstraints +=  getStateString(mas.getAbstraction().getInit(), agent) + " = 0\n";
50
		/*
51
		 * In an ideal world, this (mas.getAbstraction().getInit() == null) should not happen, but alas, 
52
		 * we live in a world which is far from ideal and as 
53
		 * we might have a public variable with private values such 
54
		 * evil things happen. There is probably no correct way to handle it.
55
		 */
56
		if(mas.getAbstraction().getInit() != null){ 
57
			stateConstraints +=  getStateString(mas.getAbstraction().getInit(), agent) + " = 0\n";
58
		}
52 59
		
53 60
		for(AbstractState s : mas.getAbstraction().getAllStates()){
54 61
			if(free){
src/main/java/cz/agents/dimaptools/costpart/MultiAbstractionLPOCPGenerator.java
48 48

  
49 49
		
50 50
		for(int var=0; var < problem.getDomain().publicVarMax; ++var){
51
			LOGGER.info(agent + ": " + var + "=" + problem.getDomain().humanizeVar(var));
52
			LOGGER.info(agent + ": " + 9 + "=" + problem.getDomain().humanizeVal(9));
53
			LOGGER.info("init: " + problem.initState);
54
			LOGGER.info(problem.getDomain() +", PUBLIC:" +problem.getDomain().publicVarMax);
51 55
			AtomicProjection ap = new AtomicProjection(problem,var);
52 56
			if(LOGGER.isInfoEnabled())LOGGER.info(agent + "(public): " + ap);
53 57
			projections.get(agent).put(var, ap);
......
66 70
			
67 71
			Abstraction abs = projections.get(agent).get(var);
68 72
		
69
			stateConstraints +=  getStateString(abs.getInit(),var, agent) + " = 0\n";
73
			if(abs.getInit() != null){ 
74
				stateConstraints +=  getStateString(abs.getInit(),var, agent,problem) + " = 0\n";
75
			}
70 76
			
71 77
			for(AbstractState s : abs.getAllStates()){
72 78
				if(free){
73
					bounds += getStateString(s,var,agent) + " >= -10000\n";
79
					bounds += getStateString(s,var,agent,problem) + " >= -10000\n";
74 80
				}else{
75
					bounds += getStateString(s,var,agent) + " >= 0\n";
81
					bounds += getStateString(s,var,agent,problem) + " >= 0\n";
76 82
				}
77 83
				if(s.isGoalState()){
78
					stateConstraints +=  getHeuristicString(agent,var) + " - " + getStateString(s,var,agent) + " <= 0\n";
84
					stateConstraints +=  getHeuristicString(agent,var) + " - " + getStateString(s,var,agent,problem) + " <= 0\n";
79 85
				}
80 86
			}
81 87
			
......
83 89
				for(int l : e.getLabels()){
84 90
					LOGGER.info(agent + " action: " + l);
85 91
					String act =  getActionString(problem.getAction(l),var,agent);
86
					stateConstraints += getStateString(e.getTo(),var,agent) + " - " + getStateString(e.getFrom(),var,agent) + " - " + act + " <= 0\n";
92
					stateConstraints += getStateString(e.getTo(),var,agent,problem) + " - " + getStateString(e.getFrom(),var,agent,problem) + " - " + act + " <= 0\n";
87 93
				}
88 94
			}
89 95
		
......
109 115
		for(Action a : problem.getAllActions()){
110 116
			if(a.isPublic()){
111 117
				
112
				float sumCost = 0;
113
				for(String ag : agents){
114
					for(int var : projections.get(problem.agent).keySet()){
115
						if(sol.hasVariable(getActionString(a,var,ag))){
116
							sumCost += sol.getVariableValue(getActionString(a,var,ag));
117
						}
118
					}
119
				}
120
				
121
				float altCost = 0; //oldCost/agents.size()
122
//				float altCost = a.getCost()/agents.size();
123
				if(a.isProjection()){
124
					altCost = a.getCost()/((float)agents.size()-1f);
125
				}else{
126
					altCost = 0;
127
				}
128
				
129 118
				float oldCost = a.getCost();
130 119
				float cpCost = 0;
131 120
				for(int var : projections.get(problem.agent).keySet()){
132 121
					cpCost += sol.getVariableValue(getActionString(a,var,problem.agent));
133 122
				}
134
				float newCost = sumCost==0 ? altCost : cpCost;
123
				float newCost =  cpCost;
135 124
				a.setCost(newCost);
136 125
				LOGGER.info("UPDATE("+a.hashCode()+"): "+oldCost+" -> "+newCost + " ("+a+")");
126
//				LOGGER.info("UPDATE("+a.hashCode()+"): "+oldCost+" -> "+newCost + " ("+a+")" +", cpCost:"+cpCost+", altCost:"+altCost);
137 127
			}
138 128
		}
139 129
	}
......
160 150
		return "h_"+var+"_"+agentName;
161 151
	}
162 152
	
163
	private String getStateString(AbstractState s,int var, String agent){
164
		String l =  s.hashCode()+"_"+var+"_"+agent;
153
	private String getStateString(AbstractState s,int var, String agent, Problem prob){
154
		String l;
155
		if(prob.getDomain().isPublicVar(var)){
156
			l =  s.hashCode()+"_"+var;
157
		}else{
158
			l =  s.hashCode()+"_"+var+"_"+agent;
159
		}
160
		
165 161

  
166 162
//		String l =  s.hashCode()+"_"+var;
167 163
		
src/main/java/cz/agents/dimaptools/heuristic/abstractions/Abstraction.java
187 187
	@Override
188 188
	public String toString() {
189 189
		String st = "Abstraction:\n";
190
		st += " States (init="+initState.hashCode()+"):\n";
190
		if(initState != null){
191
			st += " States (init="+initState.hashCode()+"):\n";
192
		}else{
193
			st += " States (init="+initState+"!!!):\n";
194
		}
191 195
		for(AbstractState s : states.values()){
192 196
			st += "  " + s + "\n";
193 197
		}
src/main/java/cz/agents/dimaptools/heuristic/abstractions/AtomicProjection.java
22 22
			}else{
23 23
				s.setGoalState(true);
24 24
			}
25
			if(problem.initState.getValue(var)==val){
25
			if(problem.initState.isDefined(var) && problem.initState.getValue(var)==val){
26 26
				s.setInitState(true);
27 27
			}
28 28
			this.addState(s);

Also available in: Unified diff