Your questions have been answered pretty extensively, just takes a little searching. Lots of advanced tech in GIS, analytics, advanced algorithms, and AI have made all of this pretty quantifiable and pretty fast. That's all unfortunately being used right now to make gerrymandering worse. Let's just start using it for good instead of for bullshit.
Start here:
https://fivethirtyeight.com/features/we-drew-2568-congressional-districts-by-hand-heres-how/
You'll notice scenarios that basically outline the criteria you provided. If the goal is to redraw districts in a way that is completely blind to partisan influence, #7 and #8 do that. If you think counties are an adequate representation of "communities of interest," you'd probably prefer #8 (you can switch maps at the top):
https://projects.fivethirtyeight.com/redistricting-maps/#Compact
This is also a good read if you're interested in how to do this without partisan influence, but also allowing some resource allocation capabilities:
https://phys.org/news/2017-11-algorithm-combat-gerrymandering.html
This all really isn't any different from the technology that city planners use to place resources throughout the community (link above mentions placing fire stations so you can serve the most people with the fewest resources). It's also generally the approach big chains (McDonald's etc) use to place restaurants in order to keep profitability high.
You can do something even more simple like minimize the average ratio of perimeter to area for all districts.
Our society and economy are already very good at solving these problems, and in the exact ways you described. The problem is the lack of political will to use them or advocate for them.
At some point, Dems will be the ones in control of how districts are drawn. I don't want that, and you probably don't either. Why not get on board right now and prevent the generational yoyo of partisan gerrymandering bullshit? It's terrible in both directions.