File size: 4,753 Bytes
90ca39a |
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
using AIMA.Agent.Action;
using AIMA.Agent.Percept;
using System;
using System.Collections.Generic;
namespace AIMA.Agent.Environment
{
public abstract class EnvironmentBase<T1, T2> : IEnvironmentViewNotifier, IEnvironment<T1, T2>
where T1 : IAction
where T2 : IPercept
{
//protected LinkedHashSet<EnvironmentObject> envObjects = new LinkedHashSet<EnvironmentObject>();
//protected LinkedHashSet<Agent> agents = new LinkedHashSet<Agent>();
//protected LinkedHashSet<EnvironmentView> views = new LinkedHashSet<EnvironmentView>();
protected Dictionary<IAgent<T1, T2>, double> _performanceMeasures { get; init; } = new();
public IReadOnlyDictionary<IAgent<T1, T2>, double> ReadOnlyPerformanceMeasures => _performanceMeasures;
public abstract IEnvironmentState GetCurrentState();
public abstract IEnvironmentState ExecuteAction(IAgent<T1, T2> agent, T1 action);
public abstract T2 GetPerceptSeenBy(IAgent<T1, T2> agent);
public virtual IList<IAgent<T1, T2>> GetAgents()
{
// Return as a List but also ensures the caller cannot modify
//return new List<IAgent<T1, T2>>(agents);
return null;
}
public virtual void AddAgent(IAgent<T1, T2> agent) => AddEnvironmentObject(agent);
public virtual void RemoveAgent(IAgent<T1, T2> agent) => RemoveEnvironmentObject(agent);
public virtual IList<IEnvironmentObject> GetEnvironmentObjects()
{
//// Return as a List but also ensures the caller cannot modify
//return new List<IEnvironmentObject>(envObjects);
return null;
}
public virtual void AddEnvironmentObject(IEnvironmentObject environmentObject)
{
//envObjects.Add(eo);
if (environmentObject is IAgent<T1, T2>)
{
//if (!agents.Contains(environmentObject as IAgent<T1, T2>))
//{
// agents.Add(a);
// this.updateEnvironmentViewsAgentAdded(a);
//}
}
}
public virtual void RemoveEnvironmentObject(IEnvironmentObject environmentObject)
{
//envObjects.Remove(eo);
//agents.Remove(eo);
}
public virtual void Step()
{
//foreach (IAgent<T1, T2> agent in agents)
//{
// if (agent.isAlive())
// {
// Action anAction = agent.execute(getPerceptSeenBy(agent));
// EnvironmentState es = executeAction(agent, anAction);
// updateEnvironmentViewsAgentActed(agent, anAction, es);
// }
//}
CreateExogenousChange();
}
public virtual void Step(int n)
{
for (int i = 0; i < n; i++)
{
Step();
}
}
public virtual void StepUntilDone()
{
while (!IsDone())
{
Step();
}
}
public virtual bool IsDone()
{
//foreach (Agent agent in agents)
//{
// if (agent.isAlive())
// {
// return false;
// }
//}
return true;
}
public virtual double GetPerformanceMeasure(IAgent<T1, T2> agent)
{
double? performanceMeasures = _performanceMeasures[agent];
if (!performanceMeasures.HasValue)
{
performanceMeasures = 0.0;
_performanceMeasures[agent] = performanceMeasures.Value;
}
return performanceMeasures.Value;
}
public virtual void AddEnvironmentView(IEnvironmentView<T1, T2> environmentView)
{
//views.Add(environmentView);
}
public virtual void RemoveEnvironmentView(IEnvironmentView<T1, T2> environmentView)
{
//views.Remove(ev);
}
public virtual void NotifyViews(string msg)
{
throw new NotImplementedException();
}
void CreateExogenousChange()
{
}
void UpdatePerformanceMeasure(IAgent<T1, T2> forAgent, double addTo)
{
}
void UdateEnvironmentViewsAgentAdded(IAgent<T1, T2> agent)
{
}
protected virtual void UpdateEnvironmentViewsAgentActed(IAgent<T1, T2> agent, T1 action,
IEnvironmentState state)
{
}
}
}
|