Skip to content

Commit

Permalink
A agpl-containers-bulk.ads
Browse files Browse the repository at this point in the history
M    concorde/agpl-cr-assigner-mtsp_concorde.adb
M    concorde/agpl-cr-assigner-mtsp_concorde.ads
M    agpl-cr-assigner.adb
M    agpl-gdk/agpl-gdk-managed.adb
M    agpl-cr-assigner.ads
M    agpl-cr-tasks-insertions.adb
M    agpl-cr-tasks-insertions.ads
M    agpl-cr-assignment.adb
D    agpl-htn-tasks-vectors.ads
M    agpl-cr-plan_assigner-greedy1.adb
D    agpl-htn-tasks-lists_utils.adb
M    agpl-cr-assignment.ads
M    agpl-cr-plan_assigner-greedy1.ads
M    agpl-cr-assigner-greedy_minmax_exhaustive.adb
D    agpl-htn-tasks-lists_utils.ads
M    agpl-cr-assigner-greedy_minmax_exhaustive.ads
M    agpl-cr-cost_matrix.adb
M    agpl-cr-cost_matrix.ads
M    agpl-htn-plan_node.adb
M    agpl-cr-agent.adb
M    agpl-graphs-bellman_ford.adb
M    agpl-htn-plan_node.ads
M    agpl-cr-agent.ads
M    agpl-cr-assigner-greedy_totalsum.adb
M    agpl-graphs-bellman_ford.ads
M    agpl-cr-assigner-greedy_totalsum.ads
M    agpl-cr-mutable_assignment.adb
M    agpl-htn-plan-utils-random.adb
M    agpl-htn-plan-utils-random.ads
M    agpl-cr-plan_assigner.ads
M    agpl-htn-plan.adb
M    agpl-generic_file_store.adb
D    agpl-htn-tasks-lists.ads
M    agpl-htn-plan.ads
M    agpl-generic_file_store.ads
D    agpl-cr-agent-lists.ads
M    agpl-event_queues-calendar.adb
M    agpl-event_queues-calendar.ads
D    agpl-cr-agent-vectors.ads
  • Loading branch information
mosteo committed Sep 5, 2006
1 parent d111b0d commit aca0382
Show file tree
Hide file tree
Showing 39 changed files with 281 additions and 498 deletions.
20 changes: 17 additions & 3 deletions agpl-cr-agent-lists.ads → agpl-containers-bulk.ads
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,23 @@
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
------------------------------------------------------------------------------

-- Massive instantiation of containers

with Ada.Containers.Indefinite_Doubly_Linked_Lists;
with Ada.Containers.Indefinite_Vectors;

generic
type Element_Type (<>) is private;
with function "=" (Left, Right : Element_Type) return Boolean is <>;
type Index_Type is range <>;
package Agpl.Containers.Bulk is

pragma Preelaborate;

package Lists is new Ada.Containers.Indefinite_Doubly_Linked_Lists
(Element_Type);

package Agpl.Cr.Agent.Lists is new
Ada.Containers.Indefinite_Doubly_Linked_Lists (Object'Class);
package Vectors is new Ada.Containers.Indefinite_Vectors
(Index_Type, Element_Type);

pragma Preelaborate (Agpl.Cr.Agent.Lists);
end Agpl.Containers.Bulk;
32 changes: 0 additions & 32 deletions agpl-cr-agent-vectors.ads

This file was deleted.

22 changes: 11 additions & 11 deletions agpl-cr-agent.adb
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ package body Agpl.Cr.Agent is
-------------------

function Get_Plan_Cost (This : in Object;
Tasks : in Htn.Tasks.Lists.List) return Costs
Tasks : in Htn.Tasks.Containers.Lists.List) return Costs
is
use Htn.Tasks.Lists;
use Htn.Tasks.Containers.Lists;
I : Cursor := First (Tasks);
Prev : Cursor;
Total : Costs := 0.0;
Expand Down Expand Up @@ -187,7 +187,7 @@ package body Agpl.Cr.Agent is

function Get_First_Task (This : in Object) return Htn.Tasks.Object'Class
is
use Htn.Tasks.Lists;
use Htn.Tasks.Containers.Lists;
begin
return Element (First (This.Tasks));
end Get_First_Task;
Expand All @@ -198,7 +198,7 @@ package body Agpl.Cr.Agent is

function Get_Last_Task (This : in Object) return Htn.Tasks.Object'Class
is
use Htn.Tasks.Lists;
use Htn.Tasks.Containers.Lists;
begin
return Element (Last (This.Tasks));
end Get_Last_Task;
Expand All @@ -219,7 +219,7 @@ package body Agpl.Cr.Agent is
---------------

function Has_Tasks (This : in Object) return Boolean is
use Htn.Tasks.Lists;
use Htn.Tasks.Containers.Lists;
begin
return not Is_Empty (This.Tasks);
end Has_Tasks;
Expand All @@ -238,7 +238,7 @@ package body Agpl.Cr.Agent is
---------------

function Get_Tasks (This : in Object)
return Htn.Tasks.Lists.List is
return Htn.Tasks.Containers.Lists.List is
begin
return This.Tasks;
end Get_Tasks;
Expand All @@ -259,7 +259,7 @@ package body Agpl.Cr.Agent is

procedure Modify_Task_List (This : in out Object;
Modifier : access procedure
(Tasks : in out Htn.Tasks.Lists.List))
(Tasks : in out Htn.Tasks.Containers.Lists.List))
is
begin
Modifier (This.Tasks);
Expand All @@ -270,7 +270,7 @@ package body Agpl.Cr.Agent is
---------------

procedure Set_Tasks (This : in out Object;
Tasks : in Htn.Tasks.Lists.List) is
Tasks : in Htn.Tasks.Containers.Lists.List) is
begin
This.Tasks := Tasks;
end Set_Tasks;
Expand All @@ -280,7 +280,7 @@ package body Agpl.Cr.Agent is
-----------------

procedure Remove_Task (This : in out Object; Id : in Htn.Tasks.Task_Id) is
use Htn.Tasks.Lists;
use Htn.Tasks.Containers.Lists;
use type Htn.Tasks.Task_Id;
I : Cursor := First (This.Tasks);
begin
Expand Down Expand Up @@ -308,8 +308,8 @@ package body Agpl.Cr.Agent is

procedure Print_Plan_Cost (This : in Object)
is
use Htn.Tasks.Lists;
Tasks : constant Htn.Tasks.Lists.List := This.Get_Tasks;
use Htn.Tasks.Containers.Lists;
Tasks : constant Htn.Tasks.Containers.Lists.List := This.Get_Tasks;
Total : Cr.Costs := 0.0;

Res : Ustring;
Expand Down
12 changes: 6 additions & 6 deletions agpl-cr-agent.ads
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

with Agpl.Htn.Plan;
with Agpl.Htn.Tasks;
with Agpl.Htn.Tasks.Lists;
with Agpl.Htn.Tasks.Containers;
with Agpl.Htn.Tasks.Primitive;
with Agpl.Types.Ustrings; use Agpl.Types.Ustrings;

Expand Down Expand Up @@ -93,7 +93,7 @@ package Agpl.Cr.Agent is
-- Should return Costs'Last for undoable plans, never raise Constraint_Error.

function Get_Plan_Cost (This : in Object;
Tasks : in Htn.Tasks.Lists.List) return Costs;
Tasks : in Htn.Tasks.Containers.Lists.List) return Costs;
-- Says the cost of this plan, not the one in the robot.
-- Should return Costs'Last for undoable plans, never raise Constraint_Error.

Expand All @@ -106,16 +106,16 @@ package Agpl.Cr.Agent is
function Get_Task_Count (This : in Object) return Natural;

function Get_Tasks (This : in Object)
return Htn.Tasks.Lists.List;
return Htn.Tasks.Containers.Lists.List;

procedure Modify_Task_List (This : in out Object;
Modifier : access procedure
(Tasks : in out Htn.Tasks.Lists.List));
(Tasks : in out Htn.Tasks.Containers.Lists.List));
-- Will call Modifier with a in-place modifiable task list, to avoid
-- redundant copying.

procedure Set_Tasks (This : in out Object;
Tasks : in Htn.Tasks.Lists.List);
Tasks : in Htn.Tasks.Containers.Lists.List);
-- Set all the ordered tasks that must conform the TO DO list;

function Has_Tasks (This : in Object) return Boolean;
Expand Down Expand Up @@ -165,7 +165,7 @@ private
Cost : Costs;
-- Start : Ada.Calendar.Time;

Tasks : Htn.Tasks.Lists.List;
Tasks : Htn.Tasks.Containers.Lists.List;
-- The TO DO list for this agent.

Execs : Executer_Maps.Map;
Expand Down
27 changes: 15 additions & 12 deletions agpl-cr-assigner-greedy_minmax_exhaustive.adb
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ with Agpl.Cr.Agent.Handle;
with Agpl.Cr.Assignment;
with Agpl.Cr.Tasks.Insertions;
with Agpl.Htn.Tasks;
with Agpl.Htn.Tasks.Containers;
with Agpl.Htn.Tasks.Handle;
-- with Agpl.Trace; use Agpl.Trace;
with Agpl.Trace; use Agpl.Trace;

with Ada.Containers.Indefinite_Ordered_Maps;

package body Agpl.Cr.Assigner.Greedy_Minmax_Exhaustive is

package Task_Lists renames Agpl.Htn.Tasks.Lists;
use type Agent.Lists.Cursor;
use type Task_Lists.Cursor;
use type Agent.Containers.Lists.Cursor;
use type Htn.Tasks.Containers.Lists.Cursor;
use type Htn.Tasks.Task_Id;
use type Cr.Agent.Handle.Object;
use type Htn.Tasks.Handle.Object;
Expand All @@ -51,15 +51,15 @@ package body Agpl.Cr.Assigner.Greedy_Minmax_Exhaustive is

function Assign
(This : in Object;
Agents : in Agent.Lists.List;
Tasks : in Task_Lists.List;
Agents : in Agent.Containers.Lists.List;
Tasks : in Htn.Tasks.Containers.Lists.List;
Costs : in Cr.Cost_Matrix.Object)
return Assignment.Object
is
A : Assignment.Object;
-- The result we'll return.

Pending : Task_Lists.List := Tasks;
Pending : Htn.Tasks.Containers.Lists.List := Tasks;
-- Tasks not yet assigned.

Not_Before : Int_Maps.Map;
Expand All @@ -70,7 +70,7 @@ package body Agpl.Cr.Assigner.Greedy_Minmax_Exhaustive is
-------------------------

procedure Remove_From_Pending (T : in Htn.Tasks.Object'Class) is
use Task_Lists;
use Htn.Tasks.Containers.Lists;
I : Cursor := Pending.First;
begin
while Has_Element (I) loop
Expand All @@ -95,8 +95,8 @@ package body Agpl.Cr.Assigner.Greedy_Minmax_Exhaustive is
Ct : out Cr.Costs;
Job : out Htn.Tasks.Handle.Object)
is
use Task_Lists;
T : Task_Lists.Cursor := Pending.First;
use Htn.Tasks.Containers.Lists;
T : Cursor := Pending.First;
begin
Ct := Cr.Costs'Last;
while Has_Element (T) loop
Expand Down Expand Up @@ -128,8 +128,9 @@ package body Agpl.Cr.Assigner.Greedy_Minmax_Exhaustive is

begin
-- Initialize assignment:
Log ("Starting ass", Always);
declare
use Agent.Lists;
use Agent.Containers.Lists;
I : Cursor := Agents.First;
begin
while Has_Element (I) loop
Expand All @@ -141,18 +142,20 @@ package body Agpl.Cr.Assigner.Greedy_Minmax_Exhaustive is
0);
end if;

Log ("Adding agent " & Element (I).Get_Name, Always);
A.Set_Agent (Element (I));
Next (I);
end loop;
end;

-- Assign tasks:
while not Pending.Is_Empty loop
Log ("Pending:" & Pending.Length'Img, Always);
declare
Best_Cost : Cr.Costs := Cr.Costs'Last;
Best_Agent : Agent.Handle.Object;
Best_Task : Htn.Tasks.Handle.Object;
use Agent.Lists;
use Agent.Containers.Lists;
I : Cursor := Agents.First;
begin
while Has_Element (I) loop
Expand Down
4 changes: 2 additions & 2 deletions agpl-cr-assigner-greedy_minmax_exhaustive.ads
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ package Agpl.Cr.Assigner.Greedy_Minmax_Exhaustive is

function Assign
(This : in Object;
Agents : in Agent.Lists.List;
Tasks : in Htn.Tasks.Lists.List;
Agents : in Agent.Containers.Lists.List;
Tasks : in Htn.Tasks.Containers.Lists.List;
Costs : in Cr.Cost_Matrix.Object)
return Assignment.Object;

Expand Down
28 changes: 14 additions & 14 deletions agpl-cr-assigner-greedy_totalsum.adb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ with Agpl.Htn.Tasks;

package body Agpl.Cr.Assigner.Greedy_Totalsum is

package Task_Lists renames Agpl.Htn.Tasks.Lists;
use type Agent.Lists.Cursor;
package Task_Lists renames Agpl.Htn.Tasks.Containers.Lists;
use type Agent.Containers.Lists.Cursor;
use type Task_Lists.Cursor;

------------
Expand All @@ -41,7 +41,7 @@ package body Agpl.Cr.Assigner.Greedy_Totalsum is

function Assign
(This : in Object;
Agents : in Agent.Lists.List;
Agents : in Agent.Containers.Lists.List;
Tasks : in Task_Lists.List;
Costs : in Cr.Cost_Matrix.Object)
return Assignment.Object
Expand All @@ -51,7 +51,7 @@ package body Agpl.Cr.Assigner.Greedy_Totalsum is
A : Assignment.Object;
-- The result we'll return.

Agts : Agent.Lists.List := Agents;
Agts : Agent.Containers.Lists.List := Agents;
-- Modifiable copy.

Pending : Task_Lists.List := Tasks;
Expand All @@ -65,7 +65,7 @@ package body Agpl.Cr.Assigner.Greedy_Totalsum is

procedure Less_Costly
(Ag : in Agent.Object'Class;
Best : out Htn.Tasks.Lists.Cursor;
Best : out Htn.Tasks.Containers.Lists.Cursor;
Cost : out Cr.Costs)
is
use Task_Lists;
Expand All @@ -92,17 +92,17 @@ package body Agpl.Cr.Assigner.Greedy_Totalsum is
-- Best_Combo --
----------------

procedure Best_Combo (Best_Agent : out Agent.Lists.Cursor;
Best_Task : out Htn.Tasks.Lists.Cursor)
procedure Best_Combo (Best_Agent : out Agent.Containers.Lists.Cursor;
Best_Task : out Htn.Tasks.Containers.Lists.Cursor)
is
use Agent.Lists;
use Agent.Containers.Lists;
I : Cursor := First (Agts);
Best_Cost : Cr.Costs := Cr.Costs'Last;
begin
while I /= No_Element loop
declare
Agent_Cost : Cr.Costs;
Agent_Task : Htn.Tasks.Lists.Cursor;
Agent_Task : Htn.Tasks.Containers.Lists.Cursor;
begin
Less_Costly (Element (I), Agent_Task, Agent_Cost);
if Agent_Task /= Task_Lists.No_Element and then
Expand All @@ -118,20 +118,20 @@ package body Agpl.Cr.Assigner.Greedy_Totalsum is

-- if Has_Element (Best_Agent) then
-- Log ("Best Agent: " & Element (Best_Agent).Get_Name, Always);
-- Log ("Best Task : " & Htn.Tasks.Lists.Element (Best_Task).To_String, Always);
-- Log ("Best Task : " & Htn.Tasks.Containers.Element (Best_Task).To_String, Always);
-- Log ("Best Cost :" & Strings.To_String (Float (Best_Cost)), Always);
-- end if;
end Best_Combo;

Best_Agent : Agent.Lists.Cursor;
Best_Agent : Agent.Containers.Lists.Cursor;
Best_Task : Task_Lists.Cursor;
begin
while not Pending.Is_Empty loop

-- Select the agent with a less costly task:
Best_Combo (Best_Agent, Best_Task);

if Best_Agent = Agent.Lists.No_Element then
if Best_Agent = Agent.Containers.Lists.No_Element then
return Cr.Assignment.Invalid_Assignment;
end if;

Expand All @@ -143,9 +143,9 @@ package body Agpl.Cr.Assigner.Greedy_Totalsum is
end Assign;
begin
Assignment.Add (A,
Agent.Lists.Element (Best_Agent),
Agent.Containers.Lists.Element (Best_Agent),
Task_Lists.Element (Best_Task));
Agent.Lists.Update_Element (Agts, Best_Agent, Assign'Access);
Agent.Containers.Lists.Update_Element (Agts, Best_Agent, Assign'Access);
end;

-- Remove assigned task.
Expand Down
Loading

0 comments on commit aca0382

Please sign in to comment.