private List <Tuple <int, int> > SetSocialLaw(List <string> messages) { if (!messages.Exists(m => FibaAcl.GetPerformative(m) == "inform")) { return(null); } var informMsg = messages.First(m => FibaAcl.GetPerformative(m) == "inform"); var content = FibaAcl.MessageToDict(FibaAcl.GetInnerMessage(informMsg)); var directive = content["content"]; var temp = directive.Substring(directive.IndexOf('(') + 1, directive.Length - directive.IndexOf('(') - 2); var pos = temp.Split(','); var posTuple = new Tuple <int, int>(int.Parse(pos[0]), int.Parse(pos[1])); var colsTuple = new Tuple <int, int>(posTuple.Item2, posTuple.Item2 + _room.GetLength(1) / Platform.Directory.Count - 1); var result = new List <Tuple <int, int> >(); var startRow = _room.GetLength(0) - 1; var dx = -1; // Generate path to clean for (var col = colsTuple.Item1; col <= colsTuple.Item2; col++) { startRow = startRow == _room.GetLength(0) - 1 ? 0 : _room.GetLength(0) - 1; dx = dx == -1 ? 1 : -1; for (var row = startRow; row < _room.GetLength(0) && row >= 0; row += dx) { result.Add(new Tuple <int, int>(row, col)); } } return(result); }
public void Bid(IEnumerable <string> tasks) { var n = _room.GetLength(0); _wishList.Clear(); foreach (var task in tasks) { var innerMessage = FibaAcl.GetInnerMessage(task); var messageDict = FibaAcl.MessageToDict(innerMessage); var content = messageDict["content"]; var subtask = content.Substring(0, content.IndexOf('(')); var cols = new string[2]; switch (subtask) { case "clean": var temp = content.Substring(content.IndexOf('(') + 1, content.Length - content.IndexOf('(') - 2); cols = temp.Split(','); break; } var colRange = new Tuple <int, int>(int.Parse(cols[0]), int.Parse(cols[1])); for (var i = colRange.Item1; i < colRange.Item2; i++) { // Distance to extreme points for each column var end1 = new Tuple <int, int>(0, i); var end2 = new Tuple <int, int>(n - 1, i); var dist1 = ManhattanDistance(end1, new Tuple <int, int>(X, Y)); var dist2 = ManhattanDistance(end2, new Tuple <int, int>(X, Y)); _wishList.Add(new Tuple <double, Tuple <int, int> >(dist1, end1)); _wishList.Add(new Tuple <double, Tuple <int, int> >(dist2, end2)); } } _wishList.Sort(Comparison); foreach (var bid in _wishList) { Language.Message(Performative.Proposal, Id.ToString(), Platform.Manager.Id.ToString(), bid.Item1 + "," + bid.Item2.Item1 + "," + bid.Item2.Item2); } }
private void Run() { _messageBoardWin = new Messaging(Id.ToString()) { StartPosition = FormStartPosition.WindowsDefaultLocation, BackColor = Color, Size = new Size(300, 300), Text = Id.ToString(), Enabled = true }; Language = new FibaAcl(_messageBoardWin.Proxy); _messageBoardWin.Show(); ReactionTime = new Timer { Enabled = true, Interval = 1000 }; ReactionTime.Tick += ReactionTimeOnTick; }
public static void Awarding(List <string> messages, MasCleaningAgent manager, IEnumerable <MasCleaningAgent> contractors, CleaningTask task, FibaAcl language) { var agentsAssigned = new List <Tuple <MasCleaningAgent, Tuple <int, int> > >(); var messagesToDict = messages.ConvertAll(FibaAcl.MessagesToDict); // Processing bids foreach (var colRange in task.SubDivide) { var firstCol = colRange.Item1; var secondCol = colRange.Item2; var bidsFirstCol = new List <KeyValuePair <MasCleaningAgent, List <Tuple <double, Tuple <int, int> > > > >(); var bidsSecondCol = new List <KeyValuePair <MasCleaningAgent, List <Tuple <double, Tuple <int, int> > > > >(); foreach (var contractor in contractors) { // Skip agents that have already been assigned if (agentsAssigned.Exists(tuple => tuple.Item1.Id == contractor.Id)) { continue; } var c = contractor; // Get messages from current contractor var messagesFromContractor = messagesToDict.FindAll(m => m.ContainsKey("from") && m["from"] == c.Id.ToString()); var bids = FibaAcl.GetContent(messagesFromContractor); // Bids to first column in the range column var bidsContractorFirstCol = bids.FindAll(b => b.Item2.Item2 == firstCol); // Bids to second column in the range column var bidsContractorSecondCol = bids.FindAll(b => b.Item2.Item2 == secondCol); if (bidsContractorFirstCol.Count > 0) { bidsFirstCol.Add( new KeyValuePair <MasCleaningAgent, List <Tuple <double, Tuple <int, int> > > >(contractor, bidsContractorFirstCol)); } if (bidsContractorSecondCol.Count > 0) { bidsSecondCol.Add( new KeyValuePair <MasCleaningAgent, List <Tuple <double, Tuple <int, int> > > >(contractor, bidsContractorSecondCol)); } } // Decide bidsFirstCol.Sort(Comparison); bidsSecondCol.Sort(Comparison); var closestAgentFirst = bidsFirstCol.FirstOrDefault(); var closestAgentSecond = bidsSecondCol.FirstOrDefault(); if (closestAgentFirst.Value != null) { closestAgentFirst.Value.Sort(Comparison); } if (closestAgentSecond.Value != null) { closestAgentSecond.Value.Sort(Comparison); } if (closestAgentFirst.Value != null && closestAgentSecond.Value != null) { if (closestAgentFirst.Value.First().Item1 >= closestAgentSecond.Value.First().Item1) { agentsAssigned.Add(new Tuple <MasCleaningAgent, Tuple <int, int> >(closestAgentSecond.Key, closestAgentSecond.Value.First(). Item2)); } else { agentsAssigned.Add(new Tuple <MasCleaningAgent, Tuple <int, int> >(closestAgentFirst.Key, closestAgentFirst.Value.First(). Item2)); } } else if (closestAgentFirst.Value == null) { agentsAssigned.Add(new Tuple <MasCleaningAgent, Tuple <int, int> >(closestAgentSecond.Key, closestAgentSecond.Value.First(). Item2)); } else { agentsAssigned.Add(new Tuple <MasCleaningAgent, Tuple <int, int> >(closestAgentFirst.Key, closestAgentFirst.Value.First(). Item2)); } } foreach (var assignment in agentsAssigned) { language.Message(Performative.Inform, manager.Id.ToString(), assignment.Item1.Id.ToString(), "clean(" + assignment.Item2.Item1 + "," + assignment.Item2.Item2 + ")"); } }
public static IEnumerable <string> Announcement(CleaningTask cleaningTask, MasCleaningAgent manager, IEnumerable <MasCleaningAgent> contractors, FibaAcl language) { var tasks = cleaningTask.SubTasks; foreach (var contractor in contractors) { foreach (var task in tasks) { language.Message(Performative.Cfp, manager.Id.ToString(), contractor.Id.ToString(), task); } } return(tasks); }