Skip to content

Commit

Permalink
Merge NetworkDatabase into ResourceNetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorisse committed Aug 20, 2020
1 parent 94a6239 commit 9f8c443
Show file tree
Hide file tree
Showing 28 changed files with 260 additions and 487 deletions.
8 changes: 4 additions & 4 deletions SourceCode/Symu/Classes/Agents/AgentId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public struct AgentId : IAgentId

public AgentId(ushort id, byte classId)
{
if (classId == 0)
{
throw new ArgumentNullException(nameof(classId));
}
//if (classId == 0)
//{
// throw new ArgumentNullException(nameof(classId));
//}

Id = id;
ClassId = new ClassId(classId);
Expand Down
14 changes: 9 additions & 5 deletions SourceCode/Symu/Classes/Agents/CognitiveAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
using Symu.Classes.Agents.Models.CognitiveTemplates;
using Symu.Classes.Blockers;
using Symu.Classes.Task.Manager;
using Symu.Common;
using Symu.Environment;
using Symu.Messaging.Manager;
using Symu.Messaging.Messages;
using Symu.Repository;
using Symu.Repository.Networks.Databases;
using Symu.Repository.Entity;
using Symu.Repository.Networks.Sphere;

#endregion
Expand Down Expand Up @@ -76,12 +74,12 @@ protected CognitiveAgent(AgentId agentId, SymuEnvironment environment, Cognitive
/// <summary>
/// If agent has an email, get the email database of the agent
/// </summary>
protected Database Email => Environment.WhitePages.MetaNetwork.Databases.GetDatabase(AgentId);
protected Database Email => Environment.WhitePages.MetaNetwork.Resources.GetResource<Database>(AgentId, AgentId) ;

/// <summary>
/// If agent has an email
/// </summary>
protected bool HasEmail => Environment.WhitePages.MetaNetwork.Databases.Exists(AgentId, AgentId);
public bool HasEmail => Environment.WhitePages.MetaNetwork.Resources.Exists(AgentId, AgentId);

//TODO => all the models should be included in the cognitive architecture
/// <summary>
Expand Down Expand Up @@ -129,6 +127,12 @@ protected override void CreateAgent(AgentId agentId, SymuEnvironment environment
throw new ArgumentNullException(nameof(environment));
}
CreateAgent(agentId, environment, environment.Organization.Templates.Standard);
// Databases are added to CognitiveAgent only, as it is a source of knowledge
foreach (var database in environment.Organization.Databases)
{
// Organization databases are used by every one
environment.WhitePages.MetaNetwork.Resources.Add(AgentId, database.AgentId, 0);
}
}

protected void CreateAgent(AgentId agentId, SymuEnvironment environment,
Expand Down
16 changes: 0 additions & 16 deletions SourceCode/Symu/Classes/Agents/ReactiveAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,11 @@
#region using directives

using System;
using System.Collections.Generic;
using System.Linq;
using Symu.Classes.Agents.Models.CognitiveModels;
using Symu.Classes.Agents.Models.CognitiveTemplates;
using Symu.Classes.Blockers;
using Symu.Classes.Task.Manager;
using Symu.Common;
using Symu.Environment;
using Symu.Messaging.Manager;
using Symu.Messaging.Messages;
using Symu.Repository;
using Symu.Repository.Networks.Databases;

#endregion

Expand Down Expand Up @@ -89,19 +82,10 @@ protected ReactiveAgent(AgentId agentId, SymuEnvironment environment)

protected virtual void CreateAgent(AgentId agentId, SymuEnvironment environment)
{
if (environment == null)
{
throw new ArgumentNullException(nameof(environment));
}

AgentId = agentId;
Environment = environment ?? throw new ArgumentNullException(nameof(environment));
Environment.AddAgent(this);
State = AgentState.NotStarted;
foreach (var database in environment.Organization.Databases)
{
environment.WhitePages.MetaNetwork.Databases.Add(AgentId, database.AgentId);
}
Created = Schedule.Step;
}

Expand Down
6 changes: 3 additions & 3 deletions SourceCode/Symu/Classes/Organization/OrganizationEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using Symu.Classes.Murphies;
using Symu.Messaging.Templates;
using Symu.Repository;
using Symu.Repository.Networks.Databases;
using Symu.Repository.Entity;
using Symu.Repository.Networks.Knowledges;

#endregion
Expand Down Expand Up @@ -61,7 +61,7 @@ public OrganizationEntity(string name) : base(0, Class, name)
/// <summary>
/// List of all databases accessible to everyone
/// </summary>
public List<DataBaseEntity> Databases { get; } = new List<DataBaseEntity>();
public List<DatabaseEntity> Databases { get; } = new List<DatabaseEntity>();

/// <summary>
/// List of all knowledges
Expand All @@ -82,7 +82,7 @@ public ushort NextEntityIndex()
/// Add a database accessible to everyone
/// </summary>
/// <param name="database"></param>
public void AddDatabase(DataBaseEntity database)
public void AddDatabase(DatabaseEntity database)
{
if (!Databases.Contains(database))
{
Expand Down
4 changes: 2 additions & 2 deletions SourceCode/Symu/Environment/SymuEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
using Symu.Messaging.Messages;
using Symu.Messaging.Tracker;
using Symu.Repository;
using Symu.Repository.Networks.Databases;
using Symu.Repository.Entity;
using Symu.Results;

#endregion
Expand Down Expand Up @@ -440,7 +440,7 @@ public void SetDatabases()
foreach (var database in Organization.Databases.Select(databaseEntity =>
new Database(databaseEntity, Organization.Models, WhitePages.MetaNetwork.Knowledge)))
{
WhitePages.MetaNetwork.Databases.AddDatabase(database);
WhitePages.MetaNetwork.Resources.Add(database);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
namespace Symu.Repository.Entity
{
/// <summary>
/// Define who is using an object and how
/// Define who is using a database and how
/// </summary>
public class Portfolio : IAgentResource
public class AgentDatabase : IAgentResource
{
public Portfolio(IAgentId agentId, byte typeOfUse, float allocation): base(agentId, typeOfUse, allocation)
public AgentDatabase(IAgentId agentId, byte typeOfUse, float allocation): base(agentId, typeOfUse, allocation)
{
}
}
Expand Down
28 changes: 28 additions & 0 deletions SourceCode/Symu/Repository/Entity/AgentPortfolio.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#region Licence

// Description: SymuBiz - Symu
// Website: https://symu.org
// Copyright: (c) 2020 laurent morisseau
// License : the program is distributed under the terms of the GNU General Public License

#endregion

#region using directives

using Symu.Common.Interfaces;
using Symu.Repository.Networks.Resources;

#endregion

namespace Symu.Repository.Entity
{
/// <summary>
/// Define who is using a component or a product and how
/// </summary>
public class AgentPortfolio : IAgentResource
{
public AgentPortfolio(IAgentId agentId, byte typeOfUse, float allocation): base(agentId, typeOfUse, allocation)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@
using Symu.Classes.Agents;
using Symu.Classes.Agents.Models.CognitiveModels;
using Symu.Classes.Organization;
using Symu.Common.Interfaces;
using Symu.Repository.Networks.Knowledges;
using Symu.Repository.Networks.Resources;

#endregion

namespace Symu.Repository.Networks.Databases
namespace Symu.Repository.Entity
{
/// <summary>
/// Database used to store and search information
/// A database is a system where agent store temporary or permanent information
/// </summary>
public class Database
public class Database : IResource
{
/// <summary>
/// the numerical reduction in knowledge if the bit is to be effected by the stochastic forgetting process
Expand All @@ -41,7 +43,12 @@ public class Database
private readonly LearningModel _learningModel;
private readonly ForgettingModel _forgettingModel;

public Database(DataBaseEntity entity, OrganizationModels organizationModels,
/// <summary>
/// Database unique Identifier
/// </summary>
public IAgentId Id => Entity.AgentId;

public Database(DatabaseEntity entity, OrganizationModels organizationModels,
NetworkKnowledges networkKnowledges)
{
if (entity == null)
Expand All @@ -54,7 +61,7 @@ public class Database
throw new ArgumentNullException(nameof(organizationModels));
}

Entity = new DataBaseEntity(entity.AgentId, entity.CognitiveArchitecture);
Entity = new DatabaseEntity(entity.AgentId, entity.CognitiveArchitecture);
_learningModel = new LearningModel((AgentId)Entity.AgentId, organizationModels, networkKnowledges,
entity.CognitiveArchitecture);
_forgettingModel = new ForgettingModel(_database, entity.CognitiveArchitecture, organizationModels);
Expand All @@ -63,7 +70,7 @@ public class Database
/// <summary>
/// Define the cognitive architecture model of this class
/// </summary>
public DataBaseEntity Entity { get; }
public DatabaseEntity Entity { get; }

public bool Exists(ushort knowledgeId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,43 @@
#region using directives

using System;

using Symu.Classes.Agents;
using Symu.Classes.Agents.Models.CognitiveModels;
using Symu.Common.Interfaces;
using Symu.Messaging.Templates;

#endregion

namespace Symu.Repository.Networks.Databases
namespace Symu.Repository.Entity
{
/// <summary>
/// Entity for DataBase class, used to store and search information during the simulation
/// </summary>
public class DataBaseEntity
public class DatabaseEntity
{
public DataBaseEntity(IAgentId agentId, CognitiveArchitecture cognitiveArchitecture)
public AgentId AgentId { get; }
public DatabaseEntity(AgentId agentId)
{
AgentId = agentId;
}

public DatabaseEntity(AgentId agentId, CognitiveArchitecture cognitiveArchitecture): this(agentId)
{
if (cognitiveArchitecture == null)
{
throw new ArgumentNullException(nameof(cognitiveArchitecture));
}

AgentId = agentId;
CognitiveArchitecture = new CognitiveArchitecture();
cognitiveArchitecture.CopyTo(CognitiveArchitecture);
}

public DataBaseEntity(IAgentId agentId, CommunicationTemplate medium)
public DatabaseEntity(AgentId agentId, CommunicationTemplate medium) : this(agentId)
{
if (medium == null)
{
throw new ArgumentNullException(nameof(medium));
}

AgentId = agentId;
CognitiveArchitecture = new CognitiveArchitecture();
// Communication
CognitiveArchitecture.MessageContent.MaximumNumberOfBitsOfBeliefToSend =
Expand All @@ -65,11 +68,6 @@ public DataBaseEntity(IAgentId agentId, CommunicationTemplate medium)
CognitiveArchitecture.KnowledgeAndBeliefs.HasKnowledge = true;
}

/// <summary>
/// Database Id
/// </summary>
public IAgentId AgentId { get; set; }

/// <summary>
/// Time to live : information are stored in the database
/// But information have a limited lifetime depending on those database
Expand Down
40 changes: 40 additions & 0 deletions SourceCode/Symu/Repository/Entity/Email.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#region Licence

// Description: SymuBiz - Symu
// Website: https://symu.org
// Copyright: (c) 2020 laurent morisseau
// License : the program is distributed under the terms of the GNU General Public License

#endregion

#region using directives

using Symu.Classes.Agents;
using Symu.Classes.Organization;
using Symu.Messaging.Templates;
using Symu.Repository.Networks.Knowledges;

#endregion

namespace Symu.Repository.Entity
{
/// <summary>
/// Database used to store and search information
/// A database is a system where agent store temporary or permanent information
/// </summary>
public class Email : Database
{
public static Email CreateInstance(AgentId agentId, OrganizationModels organizationModels, NetworkKnowledges networkKnowledges)
{
CommunicationTemplate communication = new EmailTemplate();
var entity = new DatabaseEntity(agentId, communication);
return new Email(entity, organizationModels, networkKnowledges);
}

private Email(DatabaseEntity entity, OrganizationModels organizationModels,
NetworkKnowledges networkKnowledges) : base(entity, organizationModels, networkKnowledges)
{
}

}
}
38 changes: 0 additions & 38 deletions SourceCode/Symu/Repository/Entity/Resource.cs

This file was deleted.

0 comments on commit 9f8c443

Please sign in to comment.