Skip to content
This repository has been archived by the owner on May 5, 2021. It is now read-only.

[improvement] using lombok to auto generate the variables in the graph #15

Open
glelouet opened this issue Feb 12, 2021 · 2 comments
Open

Comments

@glelouet
Copy link

Many methods in IGraphVarFactory translate a graph into a (set of) Vars.
Example: IntVar IGraphVarFactory.nbLoops(GraphVar)

The [Directed|Undirected]?GraphVar could propose this access, that is with the GraphVar parameter being this.

typically the corresponding field would be (in GraphVar)

@Getter(lazy=true) 
private final IntVar nbLoops = getModel().nbLoops(this);
  1. The @getter is from lombok, so you need to have the lombodk dependency, but set it to optional since it's not used by other projects.
  2. it also requires the getModel() to return a casted GraphModel (and the constructor to require a graphmodel)
  3. This would actually create a meaninglessvariable, and also a accessor that checks and instantiates that variable when called in a synced block.
  4. The modification is made at compile time, lombock rewrites the instruction tree. The only issue is that the sources won't show it, but your exported jar will actually contain the modified instructions.

The other trivial methods could be

@Getter(lazy=true) 
private final IntVar nbNodes = getModel().nbNodes(this);

@Getter(lazy=true) 
private final SetVar nodeSet = getModel().nodeSet(this);

@Getter(lazy=true) 
private final SetVar loopSet = getModel().loopSet(this);

if you want the accessors to keep the variable names (so nbNodes() instead of getNbNodes() ) you can add @accessors(fluent=true) to the class or the field.

@glelouet
Copy link
Author

Of course this could also be used in Choco.

@glelouet
Copy link
Author

also some methods could be auto generated in graphVar. Typically the UB, LB fields could be modified like

@getter
@nonnull
private final E UB, LB

Which will generate null-check in the constructor, and the getUB() and getLB() methods which will keep the JDoc of the field (nothing more, no lazy=true since it's required from constructor so no meaningless variable).

@glelouet glelouet changed the title [imporbvement] using lombok to auto generate the variables in the graph [improvement] using lombok to auto generate the variables in the graph Feb 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant