Skip to content

Commit

Permalink
Funciona el assignador óptimo minsum (para matrices cupiendo en la pi…
Browse files Browse the repository at this point in the history
…la!)

M    concorde/agpl-cr-assigner-mtsp_concorde.adb
M    concorde/agpl-cr-assigner-mtsp_concorde.ads
M    concorde/agpl-optimization-concorde.adb
A    agpl-cr-assigner-greedy_exhaustive.adb
M    agpl-cr.adb
A    agpl-cr-assigner-greedy_exhaustive.ads
M    agpl-cr.ads
A    agpl-cr-cost_matrix-utils.adb
A    agpl-cr-cost_matrix-utils.ads
M    agpl-cr-tasks-insertions.adb
M    agpl-cr-tasks-insertions.ads
A    agpl-cr-assigner-greedy_best_pair_tail.adb
A    agpl-cr-assigner-greedy_best_pair_tail.ads
M    agpl-cr-assignment.adb
M    agpl-cr-cost_matrix.adb
M    agpl-cr-tasks-starting_pose.adb
M    agpl-cr-cost_matrix.ads
M    agpl-cr-tasks-starting_pose.ads
D    agpl-cr-assigner-greedy_totalsum.adb
D    agpl-cr-assigner-greedy_totalsum.ads
A    agpl-cr-assigner-greedy_fifo_tail.adb
M    agpl-cr-mutable_assignment.adb
A    agpl-cr-assigner-greedy_fifo_tail.ads
A    agpl-cr-assigner-greedy_minsum_best_pair_tail.adb
A    agpl-cr-assigner-greedy_minsum_best_pair_tail.ads
M    agpl-generic_file_store.adb
  • Loading branch information
mosteo committed Sep 6, 2006
1 parent 948d677 commit 566c120
Show file tree
Hide file tree
Showing 24 changed files with 1,005 additions and 99 deletions.
130 changes: 130 additions & 0 deletions agpl-cr-assigner-greedy_best_pair_tail.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
------------------------------------------------------------------------------
-- 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. --
------------------------------------------------------------------------------

with Agpl.Chronos;
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;

package body Agpl.Cr.Assigner.Greedy_Best_Pair_Tail is

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;

------------
-- Assign --
------------

function Assign
(This : in Object;
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 : Htn.Tasks.Containers.Lists.List := Tasks;
-- Tasks not yet assigned.

-------------------------
-- Remove_From_Pending --
-------------------------

procedure Remove_From_Pending (Id : in Htn.Tasks.Task_Id) is
use Htn.Tasks.Containers.Lists;
I : Cursor := Pending.First;
begin
while Has_Element (I) loop
if Element (I).Get_Id = Id then
Pending.Delete (I);
return;
else
Next (I);
end if;
end loop;
raise Program_Error; -- Shouldn't be reached.
end Remove_From_Pending;

Timer : Agpl.Chronos.Object;
begin
-- Set agents
declare
use Cr.Agent.Containers.Lists;
procedure Add (I : Cursor) is
begin
A.Set_Agent (Element (I));
end Add;
begin
Agents.Iterate (Add'Access);
end;

-- Assign tasks:
while not Pending.Is_Empty loop
Log ("Pending:" & Pending.Length'Img &
" (Iter: " & Timer.Image & ")", Always);
Timer.Reset;

declare
New_Ass : Cr.Assignment.Object;
use Htn.Tasks;
Id_Used : Task_Id;
Cost_Total,
Cost_Delta : Cr.Costs;
begin
-- Insert best task in best agent:
Cr.Tasks.Insertions.Greedy_Tail (A,
Pending,
Costs,
This.Criterion,
New_Ass,
Id_Used,
Cost_Total,
Cost_Delta);
if Id_Used /= No_Task then
A := New_Ass;
Remove_From_Pending (Id_Used);
else
A.Set_Valid (False);
return A;
end if;
end;
end loop;

A.Set_Valid;

return A;
end Assign;

end Agpl.Cr.Assigner.Greedy_Best_Pair_Tail;
50 changes: 50 additions & 0 deletions agpl-cr-assigner-greedy_best_pair_tail.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
------------------------------------------------------------------------------
-- 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. --
------------------------------------------------------------------------------

with Agpl.Cr.Cost_Matrix;

package Agpl.Cr.Assigner.Greedy_Best_Pair_Tail is

-- Greedy heuristic that at each step will select the pair agent-task which
-- best fits the criterion.
-- The new task for an agent will be tried just at end of plan.

-- O (T * A * T) ~ O (n^3)

-- pragma Preelaborate;

type Object is new Assigner.Object with record
Criterion : Assignment_Criteria := Criterion_Time_Critical;
end record;

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

end Agpl.Cr.Assigner.Greedy_Best_Pair_Tail;
122 changes: 122 additions & 0 deletions agpl-cr-assigner-greedy_exhaustive.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
------------------------------------------------------------------------------
-- 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. --
------------------------------------------------------------------------------

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;

package body Agpl.Cr.Assigner.Greedy_Exhaustive is

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;

------------
-- Assign --
------------

function Assign
(This : in Object;
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 : Htn.Tasks.Containers.Lists.List := Tasks;
-- Tasks not yet assigned.

-------------------------
-- Remove_From_Pending --
-------------------------

procedure Remove_From_Pending (Id : in Htn.Tasks.Task_Id) is
use Htn.Tasks.Containers.Lists;
I : Cursor := Pending.First;
begin
while Has_Element (I) loop
if Element (I).Get_Id = Id then
Pending.Delete (I);
return;
else
Next (I);
end if;
end loop;
raise Program_Error; -- Shouldn't be reached.
end Remove_From_Pending;

begin
-- Set agents
declare
use Cr.Agent.Containers.Lists;
procedure Add (I : Cursor) is
begin
A.Set_Agent (Element (I));
end Add;
begin
Agents.Iterate (Add'Access);
end;

-- Assign tasks:
while not Pending.Is_Empty loop
Log ("Pending:" & Pending.Length'Img, Always);

declare
New_Ass : Cr.Assignment.Object;
Id_Used : Htn.Tasks.Task_Id;
use Htn.Tasks;
begin
-- Insert best task in best agent:
Cr.Tasks.Insertions.Greedy (A,
Pending,
Costs,
This.Criterion,
New_Ass,
Id_Used);
if Id_Used /= No_Task then
A := New_Ass;
Remove_From_Pending (Id_Used);
else
A.Set_Valid (False);
return A;
end if;
end;
end loop;

A.Set_Valid;

return A;
end Assign;

end Agpl.Cr.Assigner.Greedy_Exhaustive;
50 changes: 50 additions & 0 deletions agpl-cr-assigner-greedy_exhaustive.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
------------------------------------------------------------------------------
-- 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. --
------------------------------------------------------------------------------

with Agpl.Cr.Cost_Matrix;

package Agpl.Cr.Assigner.Greedy_Exhaustive is

-- Greedy heuristic that at each step will select the pair agent-task which
-- best fits the criterion.
-- The new task for an agent will be tried at all points of its plan.

-- O (T * A * T * T) ~ O (n^4)

pragma Preelaborate;

type Object is new Assigner.Object with record
Criterion : Assignment_Criteria := Criterion_Time_Critical;
end record;

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

end Agpl.Cr.Assigner.Greedy_Exhaustive;
Loading

0 comments on commit 566c120

Please sign in to comment.