mardi 5 juillet 2016

Design pattern to modify instances in run time to reduce memory overhead and increase flexibility

I am developing an application which builds and solves optimization models in electrical networks (Gurobi) based on the network definition provided by the user (in a WPF frontend). with c# / .net 4.5). I'd like to implement a design pattern which allows me to create many model instances (possibly thousands) which differ on only a few parameters from the base model, whilst reducing memory overhead and preserving extensibility and readability. I'd also like to be able to run multiple optimizations in parallel. I have red about the decorator and the flyweight pattern but I'm not sure which one is appropriate for my needs (or whether there is a better approach in c# / .net 4.5).

For example, consider an optimization model intended to find the shortest path in a graph (composed by nodes and edges - this is easier to explain that a problem in an electrical network, but the concepts are completely analogous). In this situation, I want to create a new shortest-path optimization model "instance" that differs from the parent model only in the cost of a given edge, or perhaps the difference is due to an edge that is unavailable, or even both and more "variations". I'd like to use a design pattern in order to easily and quickly create model "instances", without manually cloning and modifying the underlying object (e.g. "graph") and then rebuilding the optimization model from scratch.

I have thought about wrapping the underlying graph object in a decorator, and then creating decorators that change a given parameter from the graph. The optimization model builder class would then accept the decorator class and would seamlessly build a new model. I'm just not sure if this is the way forward.

Many thanks in advance!

Aucun commentaire:

Enregistrer un commentaire