Upload folder using huggingface_hub
Browse files- AIMA.csproj +8 -0
- AIMA.sln +25 -0
- Agent/Action/IAction.cs +7 -0
- Agent/Action/NoOpAction.cs +11 -0
- Agent/AgentBase.cs +26 -0
- Agent/Dynamic/DynamicAction.cs +13 -0
- Agent/Dynamic/DynamicEnvironmentState.cs +10 -0
- Agent/Dynamic/DynamicPercept.cs +29 -0
- Agent/Dynamic/DynamicState.cs +10 -0
- Agent/Environment/EnvironmentBase.cs +143 -0
- Agent/Environment/IEnvironment.cs +25 -0
- Agent/Environment/IEnvironmentObject.cs +6 -0
- Agent/Environment/IEnvironmentState.cs +6 -0
- Agent/Environment/IEnvironmentView.cs +14 -0
- Agent/Environment/IEnvironmentViewNotifier.cs +7 -0
- Agent/IAgent.cs +15 -0
- Agent/Model/IModel.cs +7 -0
- Agent/Object/IObjectWithDynamicAttributes.cs +16 -0
- Agent/Object/ObjectWithDynamicAttributesBase.cs +78 -0
- Agent/Percept/IPercept.cs +6 -0
- Agent/Program/IAgentProgram.cs +12 -0
- Agent/Program/TableDrivenAgentProgram.cs +25 -0
- Agent/State/IState.cs +7 -0
- Agent/Table/IRow.cs +15 -0
- Agent/Table/ITable.cs +13 -0
- Agent/Table/TableBase.cs +18 -0
- Program.cs +3 -0
- Utility/LinkedHashSet.cs +119 -0
AIMA.csproj
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<Project Sdk="Microsoft.NET.Sdk">
|
| 2 |
+
|
| 3 |
+
<PropertyGroup>
|
| 4 |
+
<OutputType>Exe</OutputType>
|
| 5 |
+
<TargetFramework>net6.0</TargetFramework>
|
| 6 |
+
</PropertyGroup>
|
| 7 |
+
|
| 8 |
+
</Project>
|
AIMA.sln
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
Microsoft Visual Studio Solution File, Format Version 12.00
|
| 3 |
+
# Visual Studio Version 16
|
| 4 |
+
VisualStudioVersion = 16.0.31605.320
|
| 5 |
+
MinimumVisualStudioVersion = 10.0.40219.1
|
| 6 |
+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AIMA", "AIMA.csproj", "{EC1DC4B7-A05B-47CD-ACA0-66FEA4A4ACBC}"
|
| 7 |
+
EndProject
|
| 8 |
+
Global
|
| 9 |
+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
| 10 |
+
Debug|Any CPU = Debug|Any CPU
|
| 11 |
+
Release|Any CPU = Release|Any CPU
|
| 12 |
+
EndGlobalSection
|
| 13 |
+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
| 14 |
+
{EC1DC4B7-A05B-47CD-ACA0-66FEA4A4ACBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
| 15 |
+
{EC1DC4B7-A05B-47CD-ACA0-66FEA4A4ACBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
| 16 |
+
{EC1DC4B7-A05B-47CD-ACA0-66FEA4A4ACBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
| 17 |
+
{EC1DC4B7-A05B-47CD-ACA0-66FEA4A4ACBC}.Release|Any CPU.Build.0 = Release|Any CPU
|
| 18 |
+
EndGlobalSection
|
| 19 |
+
GlobalSection(SolutionProperties) = preSolution
|
| 20 |
+
HideSolutionNode = FALSE
|
| 21 |
+
EndGlobalSection
|
| 22 |
+
GlobalSection(ExtensibilityGlobals) = postSolution
|
| 23 |
+
SolutionGuid = {0CCF8634-28A7-43E8-B48C-8A69F54E8165}
|
| 24 |
+
EndGlobalSection
|
| 25 |
+
EndGlobal
|
Agent/Action/IAction.cs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
namespace AIMA.Agent.Action
|
| 2 |
+
{
|
| 3 |
+
public interface IAction
|
| 4 |
+
{
|
| 5 |
+
bool IsNoOperation();
|
| 6 |
+
}
|
| 7 |
+
}
|
Agent/Action/NoOpAction.cs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using AIMA.Agent.Action.Dynamic;
|
| 2 |
+
|
| 3 |
+
namespace AIMA.Agent.Action
|
| 4 |
+
{
|
| 5 |
+
public sealed class NoOpAction : DynamicAction
|
| 6 |
+
{
|
| 7 |
+
internal static readonly NoOpAction NO_OPERATION = new();
|
| 8 |
+
public override bool IsNoOperation() => true;
|
| 9 |
+
private NoOpAction() : base("NoOp") {}
|
| 10 |
+
}
|
| 11 |
+
}
|
Agent/AgentBase.cs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using AIMA.Agent.Action;
|
| 2 |
+
using AIMA.Agent.Percept;
|
| 3 |
+
using AIMA.Agent.Program;
|
| 4 |
+
|
| 5 |
+
namespace AIMA.Agent
|
| 6 |
+
{
|
| 7 |
+
public abstract class AgentBase<T1,T2> : IAgent<T1,T2> where T1: IAction where T2: IPercept
|
| 8 |
+
{
|
| 9 |
+
protected readonly IAgentProgram<T1,T2> _agentProgram;
|
| 10 |
+
protected AgentBase(IAgentProgram<T1, T2> agentProgram)
|
| 11 |
+
{
|
| 12 |
+
_agentProgram = agentProgram;
|
| 13 |
+
}
|
| 14 |
+
private bool Alive { get; set; }
|
| 15 |
+
public virtual T1 Execute(T2 percept)
|
| 16 |
+
{
|
| 17 |
+
if(_agentProgram is not null)
|
| 18 |
+
{
|
| 19 |
+
return _agentProgram.Execute(percept);
|
| 20 |
+
}
|
| 21 |
+
return (T1)(NoOpAction.NO_OPERATION as IAction);
|
| 22 |
+
}
|
| 23 |
+
public bool IsAlive() => Alive;
|
| 24 |
+
public virtual void SetAlive(bool alive) => Alive = alive;
|
| 25 |
+
}
|
| 26 |
+
}
|
Agent/Dynamic/DynamicAction.cs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using AIMA.Agent.Object;
|
| 2 |
+
|
| 3 |
+
namespace AIMA.Agent.Action.Dynamic
|
| 4 |
+
{
|
| 5 |
+
public class DynamicAction : ObjectWithDynamicAttributesBase, IAction
|
| 6 |
+
{
|
| 7 |
+
public const string ATTRIBUTE_NAME = "name";
|
| 8 |
+
public DynamicAction(string name) => SetAttribute(ATTRIBUTE_NAME, name);
|
| 9 |
+
public virtual bool IsNoOperation() => false;
|
| 10 |
+
public string Name => (string)GetAttribute(ATTRIBUTE_NAME);
|
| 11 |
+
public override string DescribeType => GetType().Name;
|
| 12 |
+
}
|
| 13 |
+
}
|
Agent/Dynamic/DynamicEnvironmentState.cs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using AIMA.Agent.Environment;
|
| 2 |
+
using AIMA.Agent.Object;
|
| 3 |
+
|
| 4 |
+
namespace AIMA.Agent.Dynamic
|
| 5 |
+
{
|
| 6 |
+
public class DynamicEnvironmentState : ObjectWithDynamicAttributesBase, IEnvironmentState
|
| 7 |
+
{
|
| 8 |
+
public override string DescribeType => typeof(IEnvironmentState).Name;
|
| 9 |
+
}
|
| 10 |
+
}
|
Agent/Dynamic/DynamicPercept.cs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using AIMA.Agent.Object;
|
| 2 |
+
using AIMA.Agent.Percept;
|
| 3 |
+
using System.Diagnostics;
|
| 4 |
+
|
| 5 |
+
namespace AIMA.Agent.Dynamic
|
| 6 |
+
{
|
| 7 |
+
public class DynamicPercept : ObjectWithDynamicAttributesBase, IPercept
|
| 8 |
+
{
|
| 9 |
+
public override string DescribeType => typeof(IPercept).Name;
|
| 10 |
+
public DynamicPercept(object key1, object value1)
|
| 11 |
+
{
|
| 12 |
+
SetAttribute(key1, value1);
|
| 13 |
+
}
|
| 14 |
+
public DynamicPercept(object key1, object value1, object key2, object value2)
|
| 15 |
+
{
|
| 16 |
+
SetAttribute(key1, value1);
|
| 17 |
+
SetAttribute(key2, value2);
|
| 18 |
+
}
|
| 19 |
+
public DynamicPercept(object[] keys, object[] values)
|
| 20 |
+
{
|
| 21 |
+
Debug.Assert(keys.Length == values.Length);
|
| 22 |
+
|
| 23 |
+
for (int i = 0; i < keys.Length; i++)
|
| 24 |
+
{
|
| 25 |
+
SetAttribute(keys[i], values[i]);
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
}
|
Agent/Dynamic/DynamicState.cs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using AIMA.Agent.Object;
|
| 2 |
+
using AIMA.Agent.State;
|
| 3 |
+
|
| 4 |
+
namespace AIMA.Agent.Dynamic
|
| 5 |
+
{
|
| 6 |
+
public class DynamicState : ObjectWithDynamicAttributesBase, IState
|
| 7 |
+
{
|
| 8 |
+
public override string DescribeType => typeof(IState).Name;
|
| 9 |
+
}
|
| 10 |
+
}
|
Agent/Environment/EnvironmentBase.cs
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using AIMA.Agent.Action;
|
| 2 |
+
using AIMA.Agent.Percept;
|
| 3 |
+
using System;
|
| 4 |
+
using System.Collections.Generic;
|
| 5 |
+
|
| 6 |
+
namespace AIMA.Agent.Environment
|
| 7 |
+
{
|
| 8 |
+
public abstract class EnvironmentBase<T1, T2> : IEnvironmentViewNotifier, IEnvironment<T1, T2>
|
| 9 |
+
where T1 : IAction
|
| 10 |
+
where T2 : IPercept
|
| 11 |
+
{
|
| 12 |
+
//protected LinkedHashSet<EnvironmentObject> envObjects = new LinkedHashSet<EnvironmentObject>();
|
| 13 |
+
|
| 14 |
+
//protected LinkedHashSet<Agent> agents = new LinkedHashSet<Agent>();
|
| 15 |
+
|
| 16 |
+
//protected LinkedHashSet<EnvironmentView> views = new LinkedHashSet<EnvironmentView>();
|
| 17 |
+
|
| 18 |
+
protected Dictionary<IAgent<T1, T2>, double> _performanceMeasures { get; init; } = new();
|
| 19 |
+
public IReadOnlyDictionary<IAgent<T1, T2>, double> ReadOnlyPerformanceMeasures => _performanceMeasures;
|
| 20 |
+
public abstract IEnvironmentState GetCurrentState();
|
| 21 |
+
public abstract IEnvironmentState ExecuteAction(IAgent<T1, T2> agent, T1 action);
|
| 22 |
+
public abstract T2 GetPerceptSeenBy(IAgent<T1, T2> agent);
|
| 23 |
+
public virtual IList<IAgent<T1, T2>> GetAgents()
|
| 24 |
+
{
|
| 25 |
+
// Return as a List but also ensures the caller cannot modify
|
| 26 |
+
//return new List<IAgent<T1, T2>>(agents);
|
| 27 |
+
return null;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
public virtual void AddAgent(IAgent<T1, T2> agent) => AddEnvironmentObject(agent);
|
| 31 |
+
|
| 32 |
+
public virtual void RemoveAgent(IAgent<T1, T2> agent) => RemoveEnvironmentObject(agent);
|
| 33 |
+
public virtual IList<IEnvironmentObject> GetEnvironmentObjects()
|
| 34 |
+
{
|
| 35 |
+
//// Return as a List but also ensures the caller cannot modify
|
| 36 |
+
//return new List<IEnvironmentObject>(envObjects);
|
| 37 |
+
return null;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
public virtual void AddEnvironmentObject(IEnvironmentObject environmentObject)
|
| 41 |
+
{
|
| 42 |
+
//envObjects.Add(eo);
|
| 43 |
+
if (environmentObject is IAgent<T1, T2>)
|
| 44 |
+
{
|
| 45 |
+
//if (!agents.Contains(environmentObject as IAgent<T1, T2>))
|
| 46 |
+
//{
|
| 47 |
+
// agents.Add(a);
|
| 48 |
+
// this.updateEnvironmentViewsAgentAdded(a);
|
| 49 |
+
//}
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
public virtual void RemoveEnvironmentObject(IEnvironmentObject environmentObject)
|
| 54 |
+
{
|
| 55 |
+
//envObjects.Remove(eo);
|
| 56 |
+
//agents.Remove(eo);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
public virtual void Step()
|
| 60 |
+
{
|
| 61 |
+
//foreach (IAgent<T1, T2> agent in agents)
|
| 62 |
+
//{
|
| 63 |
+
// if (agent.isAlive())
|
| 64 |
+
// {
|
| 65 |
+
// Action anAction = agent.execute(getPerceptSeenBy(agent));
|
| 66 |
+
// EnvironmentState es = executeAction(agent, anAction);
|
| 67 |
+
// updateEnvironmentViewsAgentActed(agent, anAction, es);
|
| 68 |
+
// }
|
| 69 |
+
//}
|
| 70 |
+
CreateExogenousChange();
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
public virtual void Step(int n)
|
| 74 |
+
{
|
| 75 |
+
for (int i = 0; i < n; i++)
|
| 76 |
+
{
|
| 77 |
+
Step();
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
public virtual void StepUntilDone()
|
| 82 |
+
{
|
| 83 |
+
while (!IsDone())
|
| 84 |
+
{
|
| 85 |
+
Step();
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
public virtual bool IsDone()
|
| 90 |
+
{
|
| 91 |
+
//foreach (Agent agent in agents)
|
| 92 |
+
//{
|
| 93 |
+
// if (agent.isAlive())
|
| 94 |
+
// {
|
| 95 |
+
// return false;
|
| 96 |
+
// }
|
| 97 |
+
//}
|
| 98 |
+
return true;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
public virtual double GetPerformanceMeasure(IAgent<T1, T2> agent)
|
| 102 |
+
{
|
| 103 |
+
double? performanceMeasures = _performanceMeasures[agent];
|
| 104 |
+
if (!performanceMeasures.HasValue)
|
| 105 |
+
{
|
| 106 |
+
performanceMeasures = 0.0;
|
| 107 |
+
_performanceMeasures[agent] = performanceMeasures.Value;
|
| 108 |
+
}
|
| 109 |
+
return performanceMeasures.Value;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
public virtual void AddEnvironmentView(IEnvironmentView<T1, T2> environmentView)
|
| 113 |
+
{
|
| 114 |
+
//views.Add(environmentView);
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
public virtual void RemoveEnvironmentView(IEnvironmentView<T1, T2> environmentView)
|
| 118 |
+
{
|
| 119 |
+
//views.Remove(ev);
|
| 120 |
+
}
|
| 121 |
+
public virtual void NotifyViews(string msg)
|
| 122 |
+
{
|
| 123 |
+
throw new NotImplementedException();
|
| 124 |
+
}
|
| 125 |
+
void CreateExogenousChange()
|
| 126 |
+
{
|
| 127 |
+
|
| 128 |
+
}
|
| 129 |
+
void UpdatePerformanceMeasure(IAgent<T1, T2> forAgent, double addTo)
|
| 130 |
+
{
|
| 131 |
+
|
| 132 |
+
}
|
| 133 |
+
void UdateEnvironmentViewsAgentAdded(IAgent<T1, T2> agent)
|
| 134 |
+
{
|
| 135 |
+
|
| 136 |
+
}
|
| 137 |
+
protected virtual void UpdateEnvironmentViewsAgentActed(IAgent<T1, T2> agent, T1 action,
|
| 138 |
+
IEnvironmentState state)
|
| 139 |
+
{
|
| 140 |
+
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
}
|
Agent/Environment/IEnvironment.cs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using AIMA.Agent.Action;
|
| 2 |
+
using AIMA.Agent.Percept;
|
| 3 |
+
using System.Collections.Generic;
|
| 4 |
+
|
| 5 |
+
namespace AIMA.Agent.Environment
|
| 6 |
+
{
|
| 7 |
+
public interface IEnvironment<T1,T2> where T1 : IAction where T2 : IPercept
|
| 8 |
+
{
|
| 9 |
+
IReadOnlyDictionary<IAgent<T1, T2>, double> ReadOnlyPerformanceMeasures { get; }
|
| 10 |
+
IList<IAgent<T1,T2>> GetAgents();
|
| 11 |
+
void AddAgent(IAgent<T1,T2> agent);
|
| 12 |
+
void RemoveAgent(IAgent<T1,T2> agent);
|
| 13 |
+
IList<IEnvironmentObject> GetEnvironmentObjects();
|
| 14 |
+
void AddEnvironmentObject(IEnvironmentObject environmentObject);
|
| 15 |
+
void RemoveEnvironmentObject(IEnvironmentObject environmentObject);
|
| 16 |
+
void Step();
|
| 17 |
+
void Step(int n);
|
| 18 |
+
void StepUntilDone();
|
| 19 |
+
bool IsDone();
|
| 20 |
+
double GetPerformanceMeasure(IAgent<T1,T2> agent);
|
| 21 |
+
void AddEnvironmentView(IEnvironmentView<T1,T2> environmentView);
|
| 22 |
+
void RemoveEnvironmentView(IEnvironmentView<T1,T2> environmentView);
|
| 23 |
+
void NotifyViews(string message);
|
| 24 |
+
}
|
| 25 |
+
}
|
Agent/Environment/IEnvironmentObject.cs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
namespace AIMA.Agent.Environment
|
| 2 |
+
{
|
| 3 |
+
public interface IEnvironmentObject
|
| 4 |
+
{
|
| 5 |
+
}
|
| 6 |
+
}
|
Agent/Environment/IEnvironmentState.cs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
namespace AIMA.Agent.Environment
|
| 2 |
+
{
|
| 3 |
+
public interface IEnvironmentState
|
| 4 |
+
{
|
| 5 |
+
}
|
| 6 |
+
}
|
Agent/Environment/IEnvironmentView.cs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using AIMA.Agent.Action;
|
| 2 |
+
using AIMA.Agent.Percept;
|
| 3 |
+
|
| 4 |
+
namespace AIMA.Agent.Environment
|
| 5 |
+
{
|
| 6 |
+
public interface IEnvironmentView<T1,T2>
|
| 7 |
+
where T1:IAction
|
| 8 |
+
where T2: IPercept
|
| 9 |
+
{
|
| 10 |
+
void OnNotified(string message);
|
| 11 |
+
void OnAgentAdded(IAgent<T1,T2> agent, IEnvironmentState resultingState);
|
| 12 |
+
void OnAgentActed(IAgent<T1,T2> agent, T1 action, IEnvironmentState resultingState);
|
| 13 |
+
}
|
| 14 |
+
}
|
Agent/Environment/IEnvironmentViewNotifier.cs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
namespace AIMA.Agent.Environment
|
| 2 |
+
{
|
| 3 |
+
public interface IEnvironmentViewNotifier
|
| 4 |
+
{
|
| 5 |
+
void NotifyViews(string msg);
|
| 6 |
+
}
|
| 7 |
+
}
|
Agent/IAgent.cs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using AIMA.Agent.Action;
|
| 2 |
+
using AIMA.Agent.Environment;
|
| 3 |
+
using AIMA.Agent.Percept;
|
| 4 |
+
|
| 5 |
+
namespace AIMA.Agent
|
| 6 |
+
{
|
| 7 |
+
public interface IAgent<T1,T2> : IEnvironmentObject
|
| 8 |
+
where T1:IAction
|
| 9 |
+
where T2: IPercept
|
| 10 |
+
{
|
| 11 |
+
T1 Execute(T2 percept);
|
| 12 |
+
bool IsAlive();
|
| 13 |
+
void SetAlive(bool alive);
|
| 14 |
+
}
|
| 15 |
+
}
|
Agent/Model/IModel.cs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
namespace AIMA.Agent.Model
|
| 2 |
+
{
|
| 3 |
+
public interface IModel
|
| 4 |
+
{
|
| 5 |
+
|
| 6 |
+
}
|
| 7 |
+
}
|
Agent/Object/IObjectWithDynamicAttributes.cs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System.Collections.Generic;
|
| 2 |
+
|
| 3 |
+
namespace AIMA.Agent.Object
|
| 4 |
+
{
|
| 5 |
+
public interface IObjectWithDynamicAttributes
|
| 6 |
+
{
|
| 7 |
+
IReadOnlyDictionary<object, object> ReadOnlyAttributes { get;}
|
| 8 |
+
string DescribeType { get; }
|
| 9 |
+
string DescribeAttributes();
|
| 10 |
+
HashSet<object> GetKeySet();
|
| 11 |
+
void SetAttribute(object key, object value);
|
| 12 |
+
object GetAttribute(object key);
|
| 13 |
+
object RemoveAttribute(object key);
|
| 14 |
+
public IObjectWithDynamicAttributes Copy();
|
| 15 |
+
}
|
| 16 |
+
}
|
Agent/Object/ObjectWithDynamicAttributesBase.cs
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System;
|
| 2 |
+
using System.Collections.Generic;
|
| 3 |
+
using System.Diagnostics;
|
| 4 |
+
using System.Text;
|
| 5 |
+
|
| 6 |
+
namespace AIMA.Agent.Object
|
| 7 |
+
{
|
| 8 |
+
public abstract class ObjectWithDynamicAttributesBase : IObjectWithDynamicAttributes
|
| 9 |
+
{
|
| 10 |
+
private Dictionary<object, object> Attributes { get; init; } = new();
|
| 11 |
+
public IReadOnlyDictionary<object, object> ReadOnlyAttributes => Attributes;
|
| 12 |
+
public virtual string DescribeType => GetType().Name;
|
| 13 |
+
public virtual string DescribeAttributes()
|
| 14 |
+
{
|
| 15 |
+
var stringBuildr = new StringBuilder('[');
|
| 16 |
+
bool first = true;
|
| 17 |
+
foreach (object key in Attributes.Keys)
|
| 18 |
+
{
|
| 19 |
+
if (first)
|
| 20 |
+
{
|
| 21 |
+
first = false;
|
| 22 |
+
}
|
| 23 |
+
else
|
| 24 |
+
{
|
| 25 |
+
stringBuildr.Append(", ");
|
| 26 |
+
}
|
| 27 |
+
stringBuildr.Append(key);
|
| 28 |
+
stringBuildr.Append("==");
|
| 29 |
+
stringBuildr.Append(Attributes[key]);
|
| 30 |
+
}
|
| 31 |
+
stringBuildr.Append(']');
|
| 32 |
+
return stringBuildr.ToString();
|
| 33 |
+
}
|
| 34 |
+
public virtual HashSet<object> GetKeySet() => new(Attributes.Keys);
|
| 35 |
+
public virtual void SetAttribute(object key, object value) => Attributes[key] = value;
|
| 36 |
+
public virtual object GetAttribute(object key) => Attributes[key];
|
| 37 |
+
public virtual object RemoveAttribute(object key) => Attributes.Remove(key);
|
| 38 |
+
public virtual IObjectWithDynamicAttributes Copy()
|
| 39 |
+
{
|
| 40 |
+
ObjectWithDynamicAttributesBase copy = null;
|
| 41 |
+
try
|
| 42 |
+
{
|
| 43 |
+
copy = (ObjectWithDynamicAttributesBase)GetType().GetConstructor(Type.EmptyTypes).Invoke(null);
|
| 44 |
+
foreach (object value in Attributes)
|
| 45 |
+
{
|
| 46 |
+
copy.Attributes.Add(value, Attributes[value]);
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
catch (Exception ex)
|
| 50 |
+
{
|
| 51 |
+
Debug.WriteLine(ex.ToString());
|
| 52 |
+
}
|
| 53 |
+
return copy;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
public override bool Equals(object o)
|
| 57 |
+
{
|
| 58 |
+
if (o == null || GetType() != o.GetType())
|
| 59 |
+
{
|
| 60 |
+
return base.Equals(o);
|
| 61 |
+
}
|
| 62 |
+
return Attributes.Equals(((ObjectWithDynamicAttributesBase)o).Attributes);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
public override int GetHashCode()
|
| 66 |
+
{
|
| 67 |
+
return Attributes.GetHashCode();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
public override string ToString()
|
| 71 |
+
{
|
| 72 |
+
var stringBuilder = new StringBuilder();
|
| 73 |
+
stringBuilder.Append(DescribeType);
|
| 74 |
+
stringBuilder.Append(DescribeAttributes());
|
| 75 |
+
return stringBuilder.ToString();
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
}
|
Agent/Percept/IPercept.cs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
namespace AIMA.Agent.Percept
|
| 2 |
+
{
|
| 3 |
+
public interface IPercept
|
| 4 |
+
{
|
| 5 |
+
}
|
| 6 |
+
}
|
Agent/Program/IAgentProgram.cs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using AIMA.Agent.Action;
|
| 2 |
+
using AIMA.Agent.Percept;
|
| 3 |
+
|
| 4 |
+
namespace AIMA.Agent.Program
|
| 5 |
+
{
|
| 6 |
+
public interface IAgentProgram<T1,T2>
|
| 7 |
+
where T1:IAction
|
| 8 |
+
where T2:IPercept
|
| 9 |
+
{
|
| 10 |
+
T1 Execute(T2 percept);
|
| 11 |
+
}
|
| 12 |
+
}
|
Agent/Program/TableDrivenAgentProgram.cs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using AIMA.Agent.Action;
|
| 2 |
+
using AIMA.Agent.Percept;
|
| 3 |
+
using System.Collections.Generic;
|
| 4 |
+
|
| 5 |
+
namespace AIMA.Agent.Program
|
| 6 |
+
{
|
| 7 |
+
public class TableDrivenAgentProgram<T1,T2> : IAgentProgram<T1,T2> where T1: IAction where T2:IPercept
|
| 8 |
+
{
|
| 9 |
+
private IList<T2> Percepts { get;init; } = new List<T2>();
|
| 10 |
+
//private Table<List<Percept>, System.String, Action> table;
|
| 11 |
+
private const string ACTION = "action";
|
| 12 |
+
|
| 13 |
+
public T1 Execute(T2 percept)
|
| 14 |
+
{
|
| 15 |
+
// append percept to end of percepts
|
| 16 |
+
Percepts.Add(percept);
|
| 17 |
+
|
| 18 |
+
// action <- LOOKUP(percepts, table)
|
| 19 |
+
// return action
|
| 20 |
+
//return LookupCurrentAction();
|
| 21 |
+
|
| 22 |
+
return default;
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
}
|
Agent/State/IState.cs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
namespace AIMA.Agent.State
|
| 2 |
+
{
|
| 3 |
+
public interface IState
|
| 4 |
+
{
|
| 5 |
+
|
| 6 |
+
}
|
| 7 |
+
}
|
Agent/Table/IRow.cs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System.Collections.Generic;
|
| 2 |
+
|
| 3 |
+
namespace AIMA.Agent.Table
|
| 4 |
+
{
|
| 5 |
+
public interface IRow<ColumnHeaderType, ValueType> where ValueType:struct
|
| 6 |
+
{
|
| 7 |
+
Dictionary<ColumnHeaderType, ValueType> Columns { get; init; }
|
| 8 |
+
|
| 9 |
+
public Dictionary<ColumnHeaderType, ValueType> Cells()
|
| 10 |
+
{
|
| 11 |
+
return Columns;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
}
|
| 15 |
+
}
|
Agent/Table/ITable.cs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System.Collections.Generic;
|
| 2 |
+
|
| 3 |
+
namespace AIMA.Agent.Table
|
| 4 |
+
{
|
| 5 |
+
public interface ITable<RowHeaderType, ColumnHeaderType, ValueType> where ValueType : struct
|
| 6 |
+
{
|
| 7 |
+
List<RowHeaderType> RowHeaders { get; init; }
|
| 8 |
+
List<ColumnHeaderType> ColumnHeaders { get; init; }
|
| 9 |
+
Dictionary<RowHeaderType, Dictionary<ColumnHeaderType, ValueType>> Rows { get; init; }
|
| 10 |
+
void Set(RowHeaderType r, ColumnHeaderType c, ValueType v);
|
| 11 |
+
ValueType Get(RowHeaderType r, ColumnHeaderType c);
|
| 12 |
+
}
|
| 13 |
+
}
|
Agent/Table/TableBase.cs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System.Collections.Generic;
|
| 2 |
+
|
| 3 |
+
namespace AIMA.Agent.Table
|
| 4 |
+
{
|
| 5 |
+
public abstract record TableBase<RowHeaderType, ColumnHeaderType, ValueType>(List<RowHeaderType> RowHeaders,
|
| 6 |
+
List<ColumnHeaderType> ColumnHeaders, Dictionary<RowHeaderType, Dictionary<ColumnHeaderType, ValueType>> Rows)
|
| 7 |
+
: ITable<RowHeaderType, ColumnHeaderType, ValueType> where ValueType : struct
|
| 8 |
+
{
|
| 9 |
+
|
| 10 |
+
public virtual ValueType Get(RowHeaderType r, ColumnHeaderType c)
|
| 11 |
+
{
|
| 12 |
+
return default;
|
| 13 |
+
}
|
| 14 |
+
public virtual void Set(RowHeaderType r, ColumnHeaderType c, ValueType v)
|
| 15 |
+
{
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
}
|
Program.cs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System;
|
| 2 |
+
|
| 3 |
+
Console.WriteLine("Hello World!");
|
Utility/LinkedHashSet.cs
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System;
|
| 2 |
+
using System.Collections;
|
| 3 |
+
using System.Collections.Generic;
|
| 4 |
+
using System.Linq;
|
| 5 |
+
using System.Text;
|
| 6 |
+
using System.Threading.Tasks;
|
| 7 |
+
|
| 8 |
+
namespace AIMA.Utility
|
| 9 |
+
{
|
| 10 |
+
public class LinkedHashSet<T> : ISet<T>
|
| 11 |
+
{
|
| 12 |
+
private readonly IDictionary<T, LinkedListNode<T>> _keyValuePairs;
|
| 13 |
+
private readonly LinkedList<T> _linkList;
|
| 14 |
+
public LinkedHashSet(int initialCapacity)
|
| 15 |
+
{
|
| 16 |
+
_keyValuePairs = new Dictionary<T, LinkedListNode<T>>(initialCapacity);
|
| 17 |
+
_linkList = new LinkedList<T>();
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
public LinkedHashSet()
|
| 21 |
+
{
|
| 22 |
+
_keyValuePairs = new Dictionary<T, LinkedListNode<T>>();
|
| 23 |
+
_linkList = new LinkedList<T>();
|
| 24 |
+
}
|
| 25 |
+
public int Count => throw new NotImplementedException();
|
| 26 |
+
|
| 27 |
+
public bool IsReadOnly => throw new NotImplementedException();
|
| 28 |
+
|
| 29 |
+
public bool Add(T item)
|
| 30 |
+
{
|
| 31 |
+
throw new NotImplementedException();
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
public void Clear()
|
| 35 |
+
{
|
| 36 |
+
throw new NotImplementedException();
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
public bool Contains(T item)
|
| 40 |
+
{
|
| 41 |
+
throw new NotImplementedException();
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
public void CopyTo(T[] array, int arrayIndex)
|
| 45 |
+
{
|
| 46 |
+
throw new NotImplementedException();
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
public void ExceptWith(IEnumerable<T> other)
|
| 50 |
+
{
|
| 51 |
+
throw new NotImplementedException();
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
public IEnumerator<T> GetEnumerator()
|
| 55 |
+
{
|
| 56 |
+
throw new NotImplementedException();
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
public void IntersectWith(IEnumerable<T> other)
|
| 60 |
+
{
|
| 61 |
+
throw new NotImplementedException();
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
public bool IsProperSubsetOf(IEnumerable<T> other)
|
| 65 |
+
{
|
| 66 |
+
throw new NotImplementedException();
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
public bool IsProperSupersetOf(IEnumerable<T> other)
|
| 70 |
+
{
|
| 71 |
+
throw new NotImplementedException();
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
public bool IsSubsetOf(IEnumerable<T> other)
|
| 75 |
+
{
|
| 76 |
+
throw new NotImplementedException();
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
public bool IsSupersetOf(IEnumerable<T> other)
|
| 80 |
+
{
|
| 81 |
+
throw new NotImplementedException();
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
public bool Overlaps(IEnumerable<T> other)
|
| 85 |
+
{
|
| 86 |
+
throw new NotImplementedException();
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
public bool Remove(T item)
|
| 90 |
+
{
|
| 91 |
+
throw new NotImplementedException();
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
public bool SetEquals(IEnumerable<T> other)
|
| 95 |
+
{
|
| 96 |
+
throw new NotImplementedException();
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
public void SymmetricExceptWith(IEnumerable<T> other)
|
| 100 |
+
{
|
| 101 |
+
throw new NotImplementedException();
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
public void UnionWith(IEnumerable<T> other)
|
| 105 |
+
{
|
| 106 |
+
throw new NotImplementedException();
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
void ICollection<T>.Add(T item)
|
| 110 |
+
{
|
| 111 |
+
throw new NotImplementedException();
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
IEnumerator IEnumerable.GetEnumerator()
|
| 115 |
+
{
|
| 116 |
+
throw new NotImplementedException();
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
}
|