-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Funciona el assignador óptimo minsum (para matrices cupiendo en la pi…
…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
Showing
24 changed files
with
1,005 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.