Skip to content

Commit

Permalink
M agpl-containers-bulk.ads
Browse files Browse the repository at this point in the history
A    agpl-cr-mutable_assignment-heuristics.adb
A    agpl-cr-mutable_assignment-heuristics.ads
A    agpl-cr-containers.ads
M    agpl-cr-cost_matrix-utils.adb
A    agpl-cr-cost_cache.adb
A    agpl-cr-mutable_assignment-auctions.adb
A    agpl-cr-cost_cache.ads
A    agpl-cr-mutable_assignment-auctions.ads
M    agpl-optimization-annealing-solver.adb
A    agpl-cr-mutable_assignment-or_mutations.adb
A    agpl-cr-mutable_assignment-or_mutations.ads
M    agpl-cr-cost_matrix.adb
A    agpl-cr-assignment-utils.adb
M    agpl-cr-cost_matrix.ads
A    agpl-cr-assignment-utils.ads
A    agpl-cr-mutable_assignment-moves.adb
M    agpl-cr-mutable_assignment.adb
A    agpl-cr-mutable_assignment-moves.ads
M    agpl-cr-mutable_assignment.ads
A    agpl-cr-cost_cache-handle.ads
  • Loading branch information
mosteo committed Sep 24, 2006
1 parent f54290b commit 18ef526
Show file tree
Hide file tree
Showing 21 changed files with 1,531 additions and 974 deletions.
3 changes: 3 additions & 0 deletions agpl-containers-bulk.ads
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ package Agpl.Containers.Bulk is
package Vectors is new Ada.Containers.Indefinite_Vectors
(Index_Type, Element_Type);

package String_Element_Maps is new
Ada.Containers.Indefinite_Ordered_Maps (String, Element_Type);

end Agpl.Containers.Bulk;
33 changes: 33 additions & 0 deletions agpl-cr-assignment-utils.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
with Agpl.Cr.Containers; use Agpl.Cr.Containers;

package body Agpl.Cr.Assignment.Utils is

-----------------
-- Concatenate --
-----------------

procedure Concatenate (Dst : in out Object; Src : Object) is
Agents : constant Agent_Lists.List := Src.Get_Agents;

procedure Do_It (I : Agent_Lists.Cursor) is
Ag_Src : constant Cr.Agent.Object'Class := Agent_Lists.Element (I);
begin
if Dst.Contains (Ag_Src.Get_Name) then
declare
Ag_Dst : Cr.Agent.Object'Class := Dst.Get_Agent (Ag_Src.Get_Name);
T : Task_Lists.List := Ag_Dst.Get_Tasks;
begin
Task_Utils.Concatenate (T, Ag_Src.Get_Tasks);
Ag_Dst.Set_Tasks (T);
Dst.Set_Agent (Ag_Dst);
end;
else
Dst.Set_Agent (Ag_Src);
end if;
end Do_It;

begin
Agents.Iterate (Do_It'Access);
end Concatenate;

end Agpl.Cr.Assignment.Utils;
33 changes: 33 additions & 0 deletions agpl-cr-assignment-utils.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
------------------------------------------------------------------------------
-- AGPL --
-- --
-- Copyright (C) 2003 --
-- A. Mosteo. --
-- --
-- Authors: A. Mosteo. (public@mosteo.com) --
-- --
-- If you have any questions in regard to this software, please address --
-- them to the above email. --
-- --
-- This program is free software; you can redistribute it and/or modify --
-- it under the terms of the GNU General Public License as published by --
-- the Free Software Foundation; either version 2 of the License, or (at --
-- your option) any later version. --
-- --
-- This program is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public License --
-- along with this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
------------------------------------------------------------------------------

package Agpl.Cr.Assignment.Utils is

pragma Preelaborate;

procedure Concatenate (Dst : in out Object; Src : Object);

end Agpl.Cr.Assignment.Utils;
28 changes: 28 additions & 0 deletions agpl-cr-containers.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
pragma Warnings (Off);
with Agpl.Cr.Agent.Containers;
with Agpl.Cr.Agent.Utils;
with Agpl.Htn.Tasks.Containers;
with Agpl.Htn.Tasks.Utils;

with Ada.Containers.Indefinite_Ordered_Maps;

package Agpl.Cr.Containers is

pragma Preelaborate;

package Agent_Containers renames Agpl.Cr.Agent.Containers;
package Agent_Lists renames Agent.Containers.Lists;
package Agent_Maps renames Agent.Containers.Maps;
package Agent_Vectors renames Agent.Containers.Vectors;
package Agent_Utils renames Agent.Utils;

package Task_Containers renames Agpl.Htn.Tasks.Containers;
package Task_Lists renames Agpl.Htn.Tasks.Containers.Lists;
package Task_Maps renames Agpl.Htn.Tasks.Containers.Maps;
package Task_Vectors renames Agpl.Htn.Tasks.Containers.Vectors;
package Task_Utils renames Agpl.Htn.Tasks.Utils;

package String_Cost_Maps is new
Ada.Containers.Indefinite_Ordered_Maps (String, Costs);

end Agpl.Cr.Containers;
32 changes: 32 additions & 0 deletions agpl-cr-cost_cache-handle.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
------------------------------------------------------------------------------
-- AGPL --
-- --
-- Copyright (C) 2003 --
-- A. Mosteo. --
-- --
-- Authors: A. Mosteo. (public@mosteo.com) --
-- --
-- If you have any questions in regard to this software, please address --
-- them to the above email. --
-- --
-- This program is free software; you can redistribute it and/or modify --
-- it under the terms of the GNU General Public License as published by --
-- the Free Software Foundation; either version 2 of the License, or (at --
-- your option) any later version. --
-- --
-- This program is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public License --
-- along with this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
------------------------------------------------------------------------------

-- A generic interface for cost caching strategies.

with Agpl.Generic_Handle;

package Agpl.Cr.Cost_Cache.Handle is new
Agpl.Generic_Handle (Object'Class);
55 changes: 55 additions & 0 deletions agpl-cr-cost_cache.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
with Agpl.Cr.Agent.Dummy;

package body Agpl.Cr.Cost_Cache is

-------------------
-- Get_Plan_Cost --
-------------------

function Get_Plan_Cost
(This : in Object'Class;
Agent : in Cr.Agent.Object'Class)
return Costs
is
T : constant Htn.Tasks.Containers.Lists.List := Agent.Get_Tasks;
Prev : Htn.Tasks.Task_Id := Htn.Tasks.No_Task;
use Htn.Tasks.Containers.Lists;

Total,
Partial : Cr.Costs := 0.0;
I : Htn.Tasks.Containers.Lists.Cursor := T.First;
begin
while Has_Element (I) loop
Partial := Get_Cost (This,
Cr.Agent.Get_Name (Agent),
Prev, Htn.Tasks.Get_Id (Element (I)));
if Partial = Cr.Infinite then
Total := Infinite;
else
Total := Total + Partial;
end if;
exit when Partial = Cr.Infinite;
Prev := Htn.Tasks.Get_Id (Element (I));
Next (I);
end loop;
return Total;
end Get_Plan_Cost;

-------------------
-- Get_Plan_Cost --
-------------------

function Get_Plan_Cost
(This : in Object'Class;
Agent : in String;
Tasks : in Htn.Tasks.Containers.Lists.List)
return Costs
is
Ag : Cr.Agent.Dummy.Object;
begin
Ag.Set_Name (Agent);
Ag.Set_Tasks (Tasks);
return Get_Plan_Cost (This, Ag);
end Get_Plan_Cost;

end Agpl.Cr.Cost_Cache;
57 changes: 57 additions & 0 deletions agpl-cr-cost_cache.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
------------------------------------------------------------------------------
-- AGPL --
-- --
-- Copyright (C) 2003 --
-- A. Mosteo. --
-- --
-- Authors: A. Mosteo. (public@mosteo.com) --
-- --
-- If you have any questions in regard to this software, please address --
-- them to the above email. --
-- --
-- This program is free software; you can redistribute it and/or modify --
-- it under the terms of the GNU General Public License as published by --
-- the Free Software Foundation; either version 2 of the License, or (at --
-- your option) any later version. --
-- --
-- This program is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public License --
-- along with this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
------------------------------------------------------------------------------

-- A generic interface for cost caching strategies.

with Agpl.Cr.Agent;
with Agpl.Htn.Tasks;
with Agpl.Htn.Tasks.Containers;

package Agpl.Cr.Cost_Cache is

pragma Preelaborate;

-- type Object is interface;
type Object is abstract tagged null record;

function Get_Cost
(This : in Object;
Agent : in String;
Ini : in Htn.Tasks.Task_Id;
Fin : in Htn.Tasks.Task_Id) return Costs is abstract;

function Get_Plan_Cost
(This : in Object'Class;
Agent : in Cr.Agent.Object'Class) return Costs;
-- Say the full cost of an agent plan.

function Get_Plan_Cost
(This : in Object'Class;
Agent : in String;
Tasks : in Htn.Tasks.Containers.Lists.List) return Costs;
-- Evaluate a plan with a given agent

end Agpl.Cr.Cost_Cache;
6 changes: 4 additions & 2 deletions agpl-cr-cost_matrix-utils.adb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ package body Agpl.Cr.Cost_Matrix.Utils is
Htn.Tasks.No_Task,
V.First_Element.Get_Id,
Get_Cost
(Src, Agent.Get_Name,
(Object'Class (Src),
Agent.Get_Name,
Htn.Tasks.No_Task,
V.First_Element.Get_Id));
end if;
Expand All @@ -78,7 +79,8 @@ package body Agpl.Cr.Cost_Matrix.Utils is
V.Element (I).Get_Id,
V.Element (I + 1).Get_Id,
Get_Cost
(Src, Agent.Get_Name,
(Object'Class (Src),
Agent.Get_Name,
V.Element (I).Get_Id,
V.Element (I + 1).Get_Id));
end loop;
Expand Down
4 changes: 2 additions & 2 deletions agpl-cr-cost_matrix.adb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ package body Agpl.Cr.Cost_Matrix is
Cr.Agent.Get_Name (Al.Element (A)),
Htn.Tasks.No_Task,
Htn.Tasks.Get_Id (Tl.Element (Fin)),
Get_Cost (This,
Get_Cost (Object'Class (This),
Cr.Agent.Get_Name (Al.Element (A)),
Htn.Tasks.Get_Id (Tl.Element (Ini)),
Htn.Tasks.Get_Id (Tl.Element (Fin))));
Expand Down Expand Up @@ -238,7 +238,7 @@ package body Agpl.Cr.Cost_Matrix is
I : Htn.Tasks.Containers.Lists.Cursor := T.First;
begin
while Has_Element (I) loop
Partial := Get_Cost (This,
Partial := Get_Cost (Object'Class (This),
Cr.Agent.Get_Name (Agent),
Prev, Htn.Tasks.Get_Id (Element (I)));
if Partial = Cr.Infinite then
Expand Down
7 changes: 4 additions & 3 deletions agpl-cr-cost_matrix.ads
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ with Ada.Strings.Hash;

with Agpl.Cr.Agent;
with Agpl.Cr.Agent.Containers;
with Agpl.Cr.Cost_Cache;
with Agpl.Htn.Tasks;
with Agpl.Htn.Tasks.Containers;

package Agpl.Cr.Cost_Matrix is

pragma Preelaborate;

type Object is private;
type Object is new Cost_Cache.Object with private;
-- Here we store a mapping of Agent x Start Task x End Task --> Costs
-- This structure will be later used by assigners to compute an assignation.

Expand Down Expand Up @@ -133,7 +134,7 @@ private

use Att_Maps;

type Object is record
type Object is new Cost_Cache.Object with record
Matrix : Map;
end record;

Expand All @@ -143,6 +144,6 @@ private
pragma Inline (Key);
-- Construct a suitable key for indexing.

Empty_Object : constant Object := (others => <>);
Empty_Object : constant Object := (Cost_Cache.Object with others => <>);

end Agpl.Cr.Cost_Matrix;
Loading

0 comments on commit 18ef526

Please sign in to comment.