How to use an IncrementalScoreCalculator in Optaplanner using Java-based configuration? - optaplanner

I use Optaplanner as an optimisation library. In my code, I use a ConstraintMatchAwareIncrementalScoreCalculator to calculate scores. I am trying to move away from XML configuration but I noticed that in the SolverConfig class only offers withEasyScoreCalculatorClass(Class<? extends EasyScoreCalculator>) as far as score calculators go. Is this intended? How do I set it up to use a IncrementalScoreCalculator?

I found my own answer:
new SolverConfig<>()
.withScoreDirectorFactory(new ScoreDirectorFactoryConfig()
.withIncrementalScoreCalculatorClass(MyScoreCalculator.class)
)

Related

Is there a way to find where the internal classes are moved

We are migrating our application from Eclipse Indigo to Photon and I need help find a solution or alternate for a particular class which is present in Indigo but not in Photon.
The class we are trying to figure out is org.eclipse.ui.internal.navigator.AdaptabilityUtility.
Since it is an Internal class it is not available. But we had no luck finding an alternate.
Only one function of the class is used :
IAdaptable openable = (IAdaptable) AdaptabilityUtility.getAdapter(
selection.getFirstElement(), IResource.class);
If someone knows an alternative method which can be used here, it will be a great help.
Eclipse internals were completely rewritten for Eclipse 4 so in general there may not be exact alternatives for internal classes which were never part of the official API.
However for AdaptabilityUtility it looks like the current org.eclipse.core.runtime.Adapters class should work:
IResource resource = Adapters.adapt(selection.getFirstElement(), IResource.class);
Adapters.adapt uses generics so casts are not needed. Adapters is not internal so it is an official API.

Is there a Rhinomock version of AutoConfiguredMoqCustomization?

I am bound to use Rhinomocks in my current project. Is there a way of setting up using Autofixture with Rhinomocks to achieve the same behaviour as when combining AutoFixture with Moq using the AutoConfiguredMoqCustomization customization?
Currently I have to do a lot of dummy mock setups in my test code as seen below. In the code i dont really care about the locations that I create. I just want the GetAllLocations method to return a random list of locations instead of null:
var f = new Fixture();
var masterDataProvider = MockRepository.GenerateStub<IMasterDataProvider>();
masterDataProvider.Stub(x => x.GetAllLocations()).Return(f.CreateMany<Location>());
f.Inject(masterDataProvider);
The various Glue Libraries for AutoFixture don't have full feature parity. AutoConfiguredMoqCustomization is one of the features that are only partially ported to other Glue Libraries. IIRC, it's only available for Moq and one other dynamic mock library.
So the short answer is that no, this feature isn't available for Rhino Mocks.
Original answer:
Yes, you can use AutoFixture.AutoRhinoMocks instead of AutoFixture.AutoMoq. It works the same way, but some of the type names are different - for example, the ICustomization you should use is called AutoRhinoMockCustomization.

Projecting an instance from a A4Solution

I'm trying to make a new UI to visualize my Alloy instances. I've got an A4Solution and have been successful in extracting atoms, relations, checking atom signatures BUT I can't seem to understand how to project the instance on some sig.
I've noticed that I can try to use the edu.mit.csail.sdg.alloy4viz.AlloyInstance, I've got options to project there, but that'd imply in starting over, from a different angle.
Would that be the way to go? I'd prefer to extract that from the A4Solution object.
Thanks
You might want to look at the edu.mit.csail.sdg.alloy4viz.StaticProjector class and its project methods---that's how the Alloy Visualizer implements projections. If your visualization uses the edu.mit.csail.sdg.alloy4viz.AlloyModel class, you should be able to reuse the existing code in StaticProjector; from your post it seems, however, that you'd prefer not use any of the alloy4viz classes, in which case it should not be too difficult to understand how StaticProjector works and reapply the same ideas to your project. Or you could convert an A4Solution object to an AlloyInstance[1] and build your visualizer around the alloy4viz classes, which, in my opinion, would be a good way to go about your project.
[1] something like:
a4sol.writeXML("instance.xml")
AlloyInstance inst = StaticInstanceReader.parseInstance(new File("instance.xml"));

NSGA-II implementation

I have studied about Non dominating sorting algorithtm (NSGA-II).
I want to use this multi objective optimization algorithm.
could anybody help me by addressing any free implementation of NSGA-II in java or matlab.
Thanks in advance
MOEA Framework is a a free and open source Java framework for Multiobjective Optimization. It has the largest collection of MOEAs of any library, including NSGA-I, NSGA-II, and NSGA-III.
I personally used it to implement and solve a Multi Objective Problem (MOP) for my Master's thesis and found it far superior to PyGMO (for python) and jMetal (in Java).
The following code demonstrates how to use the MOEA Framework API to run NSGA-II to solve the ZDT1 multiobjective problem:
import java.util.List;
import org.moeaframework.Executor;
import org.moeaframework.core.NondominatedPopulation;
import org.moeaframework.core.Solution;
public class NSGAIIExample {
public static void main(String[] args) {
// configure and run this experiment
NondominatedPopulation result = new Executor()
.withProblem("ZDT1")
.withAlgorithm("NSGAII")
.withMaxEvaluations(1000)
.distributeOnAllCores()
.run();
List<NondominatedPopulation> multiRuns = new Executor()
.withProblem("ZDT1")
.withAlgorithm("NSGAII")
.withMaxEvaluations(1000)
.distributeOnAllCores()
.runSeeds(3);
System.out.format("Obj1 Obj2%n");
for (Solution solution : result) {
System.out.format("%.5f\t%.5f%n", solution.getObjective(0),
solution.getObjective(1));
}
}
}
jMetal is the Java framework of MOEA, which NSGA-II is included in. The website is here.
This looks like what you want from Matlab
http://www.mathworks.co.uk/matlabcentral/fileexchange/10429-nsga-ii-a-multi-objective-optimization-algorithm
And here's one for Java:
http://ia-2008.googlecode.com/svn/trunk/TrabajoPracticoFinal/Implementacion/NSGA/src/jmetal/metaheuristics/nsgaII/NSGAII.java
Since it hasn't been mentioned so far: Jenetics
Jenetics is an advanced Genetic Algorithm, Evolutionary Algorithm and Genetic Programming library, respectively, written in modern day Java.
As of version 4.1.0 the jenetics.ext module offers classes for multi-objective problems. It also offers a NSGA2Selector, but (taken from the manual v4.3.0, p. 92):
Since the MOO classes are an extensions to the existing evolution Engine, the implementation doesn't exactly follow an established algorithm, like NSGA2 or SPEA2. The results and performance, described in the relevant papers, are therefore not directly comparable.
Nonetheless, this might reasonable alternative.
Have quickly read this thread and I haven't seen a mention of platEMO. Which is a matlab based optimisation platform that I have used a lot recently. The documentation and installation information can be found at:
https://github.com/BIMK/PlatEMO
It has a large amount of problems and algorithms (including NSGA-II) as standard.

Lucene numDocs and doqFreq on custom similarity class

im doing an aplication with Lucene (im a noob with it) and im facing some problems.
My aplication uses the Lucene 2.4.0 library with a custom similaraty implementation (the jar is imported)
In my app im calculating doqFreq and numDocs manually (im adding the values of all indexes and then i calculate a global value in order to use it on every query) and i want to use that values on a custom similarity implementation in order to calculate a new IDF.
The problem is that I dont know how to use (or send) the new doqFreq and numDocs values from my app on that new similarty implementation as I dont want to change luceneĀ“s code apart from this extra class.
Any suggestions or examples? I read the docs but i dont now how to aproach this :s
Thanks
You can try extending IndexReader and overriding IndexReader.docFreq() and IndexReader.numDocs(). In this subtype you can supply that you are calculating manually. I'm not sure if there are other Lucene components that are dependent on those values, so you might want to tread carefully here.