COMPLETE REVISION: Some time after I answered this question, I came across this cool trick, which allows one to achieve the goal in a much more elegant way. After I got reminded of my original code in this question, I felt that I need to update this answer to
\documentclass[varwidth]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{inimigo.dat}
x y label
52 10 a0
3 41 a1
51 52 a2
22 62 a3
36 32 a4
\end{filecontents*}
\begin{filecontents*}{pontofixo.dat}
x y label
115 45 Goal
\end{filecontents*}
\begin{filecontents*}{inicial.dat}
x y label
65 26 i0
47 37 i1
6 16 i2
44 5 i3
58 6 i4
\end{filecontents*}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{geometry}
\geometry{
paperwidth=25cm,
left=1in,right=1in,top=1in,bottom=1in
}
\pgfplotsset{% https://tex.stackexchange.com/a/75811/121799
name nodes near coords/.style={
every node near coord/.append style={
name=#1-\coordindex,
alias=#1-last,
},
},
name nodes near coords/.default=coordnode
}
\begin{document}
\begin{figure}[h]
\centering
\begin{subfigure}{.4\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[xmin=0,xmax=120,ymin=0,ymax=90, xstep=1,ystep=1,nodes near coords,enlargelimits=0.0]
\addplot +[only marks,mark=*,nodes near
coords={\labelz},
visualization depends on={value \thisrowno{2}\as\labelz},
name nodes near coords=Gol]
table{pontofixo.dat}; % this defines the coordinate (Goal)
% if I do not define it, the next sequence will throw an error
\addplot +[scatter/position=relative,only marks,mark=*,
nodes near coords={\labelz},
visualization depends on={value \thisrowno{2}\as\labelz},
name nodes near coords=a]
table{inimigo.dat};
\addplot +[scatter/position=relative,only marks,mark=*,
nodes near coords={\labelz},
visualization depends on={value \thisrowno{2}\as\labelz},
name nodes near coords=i]
table{inicial.dat};
\end{axis}
\foreach \n in {0,...,4}
{
\draw[black,thick,dashed] (a-\n.south) -- (Gol-0.south);
\draw[black,thick,dashed] (i-\n.south) -- (Gol-0.south);
}
\end{tikzpicture}
\caption{Estado inicial}
\end{subfigure}%
\centering
\begin{subfigure}{.4\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[xmin=0,xmax=120,ymin=0,ymax=90, xstep=1,ystep=1,nodes near coords,enlargelimits=0.0]
\addplot +[only marks,mark=*,nodes near
coords={\labelz},
visualization depends on={value \thisrowno{2}\as\labelz},
name nodes near coords=Gol]
table{pontofixo.dat}; % this defines the coordinate (Goal)
% if I do not define it, the next sequence will throw an error
\addplot +[scatter/position=relative,only marks,mark=*,
nodes near coords={\labelz},
visualization depends on={value \thisrowno{2}\as\labelz},
name nodes near coords=a]
table{inimigo.dat};
\addplot +[scatter/position=relative,only marks,mark=*,
nodes near coords={\labelz},
visualization depends on={value \thisrowno{2}\as\labelz},
name nodes near coords=g]
table{gbest.dat};
\end{axis}
\foreach \n in {0,...,4}
{
\draw[black,thick,dashed] (a-\n.south) -- (Gol-0.south);
\draw[black,thick,dashed] (g-\n.south) -- (Gol-0.south);
}
\end{tikzpicture}
\caption{Estado final}
\end{subfigure}%
\end{figure}
\end{document}

OLD: Here is my original solution.
\documentclass[varwidth]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{inimigo.dat}
x y label
52 10 a0
3 41 a1
51 52 a2
22 62 a3
36 32 a4
\end{filecontents*}
\begin{filecontents*}{pontofixo.dat}
x y label
115 45 Goal
\end{filecontents*}
\begin{filecontents*}{inicial.dat}
x y label
65 26 i0
47 37 i1
6 16 i2
44 5 i3
58 6 i4
\end{filecontents*}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{geometry}
\geometry{
paperwidth=25cm,
left=1in,right=1in,top=1in,bottom=1in
}
\begin{document}
\begin{figure}[h]
\centering
\begin{subfigure}{.4\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[xmin=0,xmax=120,ymin=0,ymax=90, xstep=1,ystep=1,nodes near coords,enlargelimits=0.0]
\xdef\DoLater{}
\addplot +[only marks,mark=*,nodes near
coords={\makebox[0pt]{\coordinate(\labelz) at (\myx,\myy);}\labelz},
visualization depends on={value \thisrowno{2}\as\labelz},
visualization depends on={value \thisrow{x}\as\myx},
visualization depends on={value \thisrow{y}\as\myy}]
table{pontofixo.dat}; % this defines the coordinate (Goal)
% if I do not define it, the next sequence will throw an error
\addplot +[scatter/position=relative,only marks,mark=*,
nodes near coords={\labelz\makebox[0pt]{\coordinate(\labelz) at
(\myx,\myy);
\xdef\DoLater{\DoLater,\labelz}
}}, visualization depends on={value \thisrowno{2}\as\labelz},
visualization depends on={value \thisrow{x}\as\myx},
visualization depends on={value \thisrow{y}\as\myy}]
table{inimigo.dat};
\addplot +[scatter/position=relative,only marks,mark=*,
nodes near coords={\labelz\makebox[0pt]{\coordinate(\labelz) at
(\myx,\myy);
\xdef\DoLater{\DoLater,\labelz}
}}, visualization depends on={value \thisrowno{2}\as\labelz},
visualization depends on={value \thisrow{x}\as\myx},
visualization depends on={value \thisrow{y}\as\myy}]
table{inicial.dat};
\end{axis}
\foreach \Point in \DoLater{
\ifx\Point\empty%
\relax
\else
\draw (\Point) -- (Goal);
\fi
}
\end{tikzpicture}
\caption{Estado inicial}
\end{subfigure}%
\centering
\begin{subfigure}{.4\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[xmin=0,xmax=120,ymin=0,ymax=90, xstep=1,ystep=1,nodes near coords,enlargelimits=0.0]
\xdef\DoLater{}
\addplot +[only marks,mark=*,nodes near
coords={\makebox[0pt]{\coordinate(\labelz) at (\myx,\myy);}\labelz},
visualization depends on={value \thisrowno{2}\as\labelz},
visualization depends on={value \thisrow{x}\as\myx},
visualization depends on={value \thisrow{y}\as\myy}]
table{pontofixo.dat}; % this defines the coordinate (Goal)
% if I do not define it, the next sequence will throw an error
\addplot +[scatter/position=relative,only marks,mark=*,
nodes near coords={\labelz\makebox[0pt]{\coordinate(\labelz) at
(\myx,\myy);
\xdef\DoLater{\DoLater,\labelz}
}}, visualization depends on={value \thisrowno{2}\as\labelz},
visualization depends on={value \thisrow{x}\as\myx},
visualization depends on={value \thisrow{y}\as\myy}]
table{inimigo.dat};
\addplot +[scatter/position=relative,only marks,mark=*,
nodes near coords={\labelz\makebox[0pt]{\coordinate(\labelz) at
(\myx,\myy);
\xdef\DoLater{\DoLater,\labelz}
}}, visualization depends on={value \thisrowno{2}\as\labelz},
visualization depends on={value \thisrow{x}\as\myx},
visualization depends on={value \thisrow{y}\as\myy}]
table{gbest.dat};
\end{axis}
\foreach \Point in \DoLater{
\ifx\Point\empty%
\relax
\else
\draw (\Point) -- (Goal);
\fi
}
\end{tikzpicture}
\caption{Estado final}
\end{subfigure}%
\end{figure}
\end{document}

Explanation: While the tables are parsed, coordinates are defined which have the label ... have a guess ... label
, and the coordinates are also stored in a list \DoLater
. This list is parsed outside the axis
environment (because of the delayed expansion issue) and then the connections are drawn. (Note that this version relies on the coordinate labels being unique, yet it is straightforward to add something like \coordindex
to the label to make the labels unique in future applications of this trick.)
inimigo.dat
to two more file names, I guess it is not going to work because I'll have 3 sets of identical coordinates with identical names.