I have the following function:
(defun chooseBest (TSPs dTSPs)
(let ((minim (minPos dTSPs 0 0)) (j 0) (best nil))
(loop for i in TSPs
do (cond ((= j minim) (progn (setf best i) (setq j (+ j 1))))
(t (setq j (+ j 1)))))
best))
This function receives two lists:
TSPs - a list of paths like this one:
(((1 3600 2300) (2 3100 3300))
((3 4700 5750) (22 6650 2300) (23 5400 1600)))
and a list of distances associated with these:
(distancePath1 distancePath2)
The function minPos returns the position of the list with a smaller number that is the path with smaller distance.
Given this, the chooseBest function will return the smaller path.
But I want to improve it, because it will search the whole list for the small number and it is a waste because the minim has that position. For example minim is 2, but it is evaluating a TSPs list with 100 paths, I want to return immediately on 2 and break the loop, but return doesn't work...
return: lispcookbook.github.io/cl-cookbook/iteration.html and functions to search elements in sequences (find, search, elt, index, nth… lispcookbook.github.io/cl-cookbook/…)