There's a function which takes a schedule and generates a score. Leaving a spot unfilled or scheduling someone who isn't available subtracts lots of points. Scheduling someone much more or less often than the median subtracts points based on how much of a difference there is. Scheduling someone on a day they prefer adds points, and so forth.
Then it's a simple hill-climbing algorithm starting from an empty schedule. I get people's availability and preferences into the program, hit run, and out pops a schedule.
I learned early on that I must check the result before publishing it. The algorithm itself works fine. Hill climbing probably isn't finding the absolute optimal schedule, but it does a good job. The problem, of course, is the scoring function. Sometimes it turns out to be missing some important constraint. Much more often, I need to tinker with the weights assigned to various conditions.
People assign too much agency and intelligence to computers. They are, of course, just tools. A nail gun will put a nail into whatever you point it at, whether it's drywall or flooring or feet. Likewise, a computer optimization system will optimize whatever function you tell it to, and will probably do an excellent job, but it's up to you to make sure the function accurately describes what the humans want.