I would say it's an analogy, which generally in literature implies the primary subject being compared to something more familiar, in hopes of conveying insights into the true nature of the subject.
In Tolstoy's case, it doesn't matter that his audience probably aren't particularly familiar with differential calculus. He explicitly defines the feature relevant to his analogy; exacting measurement of tiny differences enables one to graph a complex function to present a revealing image.
His purpose being to show that a true understanding of human history in the global and long-term sense can best be achieved by focussing on the minute particulars of specific incidents involving particular people at some given place and time.
Today he'd be more likely to use the analogy of a hologram, which has the interesting property that if you shatter it, you can still retrieve the whole original picture from each small part.
Unfortunately for Tolstoy (who had no great reputation as a mathematician), measuring exact values anywhere on the line of a complex function doesn't actually tell you much about what may happen elsewhere on the graph. And the smaller the piece of broken hologram you look at, the fuzzier the image you can get from it becomes. It's not an analogy that can be taken too far.
Briefly, analogy is a perceived likeness between two entities; metaphor is one “figure of speech” which you might use to communicate that likeness.
For example: you may recognize that many Greek and Shakespearean tragedies have a similar structure: a phase of increasing conflict between opposed sides or characters, a major confrontation between the opposed characters, and a phase in which the opposition is worked out and resolved in one character's victory and the other's defeat.
It may then occur to you that this structure is very like the shape of a pyramid isosceles triangle, which rises from a baseline to a central point and then falls back to its baseline. You have then perceived an analogy betweeen a temporal phenomenon and a spatial one.
To communicate this analogy, you may employ metaphors. You name the central confrontation the “climax” —this is the classical name for a figure of speech, which is itself a metaphor: the word means “ladder”. You then name the first phase the “rising action” and the fourth stage the “falling action”.
Subsequently you perceive that the rising action has its own inceptive phase, when the characters and conflicts are introduced. These don’t fit so well into the triangular analogy, so you cast about for another analogy. One that occurs to you that of a public display of new works—so you employ the metaphor “exposition”. And for the final phase, when everything has “fallen” all the way back to the “baseline” you adopt the Greek word “catastrophe”, meaning “turn or fall down” or, metaphorically, “come to an end”.
And then you publish this elegant treatment of dramatic structure to universal applause, and the critical world pays you the ultimate honor of putting your own name on the basic metaphor: it becomes known to all succeeding generations as “Freytag’s pyramid”.
Most of those succeeding generations, however, find singular deficiencies in the model. They point out, for instance, that “exposition” of new facts occurs continuously throughout a play, and that many different actions occur alongside each other. They perceive a different analogy, that between dramatic structure and a tangle of threads; and to express this analogy they employ the metaphors complication (literally, a “folding together”) for the developing action and dénouement, a French word meaning “untying”, for the conclusion.
The analogy is what is expressed; the metaphor is how it is expressed.
Note, however, that metaphor is not the only way to express analogy. You may also employ simile: instead of talking about the analogous entity instead of the primary entity you may say that your primary entity is like the analogous entity. Or you can avoid language altogether and express the analogy in graphic form, using a labeled picture.
Best Answer
The analogy/idiom is usually a variant of "That's letting the fox guard the henhouse," and I think it aptly fits the situation you describe: The fox is put into a position where it can determine an outcome that it desires. Whether the outcome is negative or positive is irrelevant to the point the analogy/idiom is making.