You can sort by distance to make sure the naked verts pull to the correct segments of the target boundary, and the corner verts to the correct corners.
To stop the faces folding over themselves, you can use the PolygonArea goal with a target area of 0.
First thing to fix is the T input on the Anchor goal.
In your definition, you had the 5 vertices of a curve as target points. That doesn’t work since you have 4 mesh corners. You can find the closest points from all 4 mesh corners like this:
I should also mention - although it is possible to prevent the foldovers with the PolygonArea goal like I showed above, the fact that they were happening in the first place often suggests the mesh topology being used is not the best fit for the shape. Here if you just add a few extra horizontal divisions either side of the hole (using InsertEdge) then it works even without PolygonArea, and gives more rectangular faces:
Yeap, putting a good solution of mesh layout is the hard part. Can you please suggest any resources for a better understanding of mesh topology?
PolygonArea is a new goal for me, and here is the result when I apply one more Solve w/ Polygon Area.
P/S: Where I can find “InsertEdge”? Is it a Rhino command or a GH component?