A deterministic computer simulation was made of a population occupying two niches. The size of the population in each niche was assumed constant, and there was gene flow between niches. The gene flow represented pollen transfer among plant populations. The basic model described one gene with two alleles, different alleles being selectively favored in different niches. This model was extended to investigate, in turn, situations where the character undergoing selection was polygenic, where there were modifiers causing linkage of the polygenes, where there were modifiers causing changes in the dominance relations of the alleles, and where genes determined assortative mating and self-fertility. Results showed that a polymorphism could be maintained particularly with high levels of selection and/or low levels of gene flow, both in single-gene and polygenic cases. Linkage modifiers spread slowly in the population, but evolution of dominance or overdominance occurred rapidly, particularly under high levels of selection and gene flow. Isolation between populations in each of the two niches could arise through assortative mating or through self-fertility. The conditions under which each of these evolutionary steps occurred were clearly defined. Selection in heterogeneous environments with migration between subhabitats was shown to occur in several qualitatively different ways ("migration-selection cycles"). The assumptions of the model and the results were discussed in relation to studies on natural and experimental populations.