Lama Ole’s answer:
When taking a human rebirth, a person will be female if the karmic bond is stronger with the father or male if it is stronger with the mother. That basically means that girls feel more drawn to the father and boys to the mother.
This can change throughout one’s life due to other karmas. I believe that the simplest solution is for the children to live with the parent who has found a new partner with a good connection to the children. This is especially true if one parent doesn’t find a new partner. A family is certainly better than a single parent, unless the bond with that parent is particularly strong.
In most cases, I recommend having an extended family, the way the Nepalese live, for example. In their culture, former partners and their new partners create two families out of one, where the children can maintain a good bond with both parents. In this situation, it is important that the former partners do not feel anger towards one another for being left. Both have to be satisfied when they separate.