What would happen if rats from different environments came together and could mate and have viable offspring?
Well, what you are describing with this question is the basis of all heredity. When two organisms mate, they take the collective pool of all their inherited traits and cross-multiply them with each other, producing offspring that present those traits in varying combinations. Sometimes, the traits that are expressed are not conducive to survival in that particular environment, so the organism does not survive. That is natures way of eliminating unsuccessful combinations of genes. The traits that do survive are the ones that are passed along for future generations. This theory is called natural selection, and served as the basis for Charles Darwins work, outlined in his book, "Origin of the Species". Species mate in an attempt to propagate their species, it is one of the necessary requirements for a species to avoid extinction. The species that have the traits that enable them to successfully master their environment are the ones that will survive.