Simple TimeWindowedVehicleRoutingSolution Example with a Problem - optaplanner

I am currently trying to implement the Optaplanner Libraries into an easy TimeWindowedVehicleRoutingSolution Example. My current code is trying to be as simple as possible and is using mostly default stuff like the vehicleRoutingSolverConfig.
public static void main(String[] args) {
SolverFactory<TimeWindowedVehicleRoutingSolution> solverFactory = SolverFactory.createFromXmlResource("test/vehicleRoutingSolverConfig.xml");
solverFactory.getSolverConfig();
Solver<TimeWindowedVehicleRoutingSolution> solver = null;
try{
solver = solverFactory.buildSolver();
}catch(Exception e){
System.out.println(e.toString());
}
// from 12/07/2018 # 12:00pm to 12/07/2018 # 12:30pm
TimeWindowedCustomer hans = new TimeWindowedCustomer();
hans.setReadyTime(1544184000);
hans.setDueTime(1544185800);
// from 12/07/2018 # 11:00pm to 12/07/2018 # 11:30pm
TimeWindowedCustomer detlef = new TimeWindowedCustomer();
detlef.setReadyTime(1544180400);
detlef.setDueTime(1544182200);
RoadLocation hansRoad = new RoadLocation();
RoadLocation detlefRoad = new RoadLocation();
RoadLocation hubRoad = new RoadLocation();
HashMap hansMap = new HashMap<RoadLocation, Double>();
//10min
hansMap.put(detlefRoad, 0.6);
//15min
hansMap.put(hubRoad, 0.9);
hansRoad.setTravelDistanceMap(hansMap);
HashMap detlefMap = new HashMap<RoadLocation, Double>();
//10min
detlefMap.put(hansRoad, 0.6);
//20min
detlefMap.put(hubRoad, 1.2);
detlefRoad.setTravelDistanceMap(detlefMap);
HashMap hubMap = new HashMap<RoadLocation, Double>();
//15min
hubMap.put(hansRoad, 0.9);
//20min
hubMap.put(detlefRoad, 1.2);
hubRoad.setTravelDistanceMap(hubMap);
TimeWindowedDepot hub = new TimeWindowedDepot();
hub.setLocation(hubRoad);
hans.setLocation(hansRoad);
detlef.setLocation(detlefRoad);
Vehicle vehicle = new Vehicle();
vehicle.setDepot(hub);
List<Customer> customers = new ArrayList<Customer>();
customers.add(detlef);
customers.add(hans);
List<Depot> depots = new ArrayList<Depot>();
depots.add(hub);
List<Vehicle> vehicles = new ArrayList<Vehicle>();
vehicles.add(vehicle);
List<Location> locations = new ArrayList<Location>();
locations.add(hansRoad);
locations.add(detlefRoad);
locations.add(hubRoad);
hans.setId(1L);
detlef.setId(2L);
hub.setId(3L);
vehicle.setId(4L);
hansRoad.setId(5L);
detlefRoad.setId(6L);
hubRoad.setId(7L);
TimeWindowedVehicleRoutingSolution problem = new TimeWindowedVehicleRoutingSolution();
problem.setCustomerList(customers);
problem.setDepotList(depots);
problem.setVehicleList(vehicles);
problem.setLocationList(locations);
problem.setDistanceType(DistanceType.ROAD_DISTANCE);
TimeWindowedVehicleRoutingSolution solution = solver.solve(problem);
for(Customer c : solution.getCustomerList()) {
TimeWindowedCustomer tc = (TimeWindowedCustomer) c;
System.out.println(tc.getArrivalTime());
}
}
The Problem I am now facing is that the timewindow isn't really considered a hard rule and therefor the suggested route arrives before the timewindow. I think I am just missing breaks that the drivers could make and from looking at the code I would think that breaks are possible, just not with my configuration. So the question would be, how to get breaks into my example.

Related

Creating a 3D Text with JReality in Java

I am trying to create a 3D Text with JReality.
At first I'm creating a PointSetFactory, which contains the point(1,0,0).
Then I'm adding the Text "Tex" to this Point. Then I create a PDF file from this Geometry. However I get only the Point but not the Text. (See picture (2)) Any idea why?
I have also tried to use the Documentation of this Library, but the example seems also not to work. the Documentation of the 3D Text in JReality.
the Result that I should get from the Program in the documentation is like in Picture (3).
#SuppressWarnings("javadoc")
public class ASD
{
public static String RESOURCE = "D:\\skalierung.U3D";
public static String RESULT ="D:\\skalierungpdf.pdf";
public static void main(String[] args) throws DocumentException, IOException {
/////////////
IndexedFaceSet ifs = Primitives.icosahedron();
SceneGraphComponent geometryNode = new SceneGraphComponent("TexTextX");
// geometryNode.setGeometry(ifs);
PointSetFactory psf_x = new PointSetFactory();
double [][] vertice_x = new double[][] { {1, 0, 0} };
psf_x.setVertexCount( vertice_x.length );
psf_x.setVertexCoordinates( vertice_x );
psf_x.update();
PointSet ps_x = psf_x.getPointSet();
int n_x=ps_x.getNumPoints();
String[] label_x = new String[n_x];
label_x[0] = "Tex";
ps_x.setVertexAttributes(Attribute.LABELS, StorageModel.STRING_ARRAY.createReadOnly(label_x));
SceneGraphComponent text_x = new SceneGraphComponent();
text_x.setName("TexTextX");
text_x.setGeometry(ps_x);
Appearance text_xAp = new Appearance();
text_xAp.setAttribute(CommonAttributes.POINT_RADIUS, 10.0);
text_xAp.setAttribute(CommonAttributes.POINT_SIZE, 10.0);
text_xAp.setAttribute(CommonAttributes.VERTEX_DRAW, true);
DefaultGeometryShader dgs_x = ShaderUtility.createDefaultGeometryShader(text_xAp, false);
dgs_x.setShowFaces(false);
dgs_x.setShowLines(false);
dgs_x.setShowPoints(true);
DefaultTextShader pts_x = (DefaultTextShader) ((DefaultPointShader)dgs_x.getPointShader()).getTextShader();
pts_x.setDiffuseColor(Color.RED);
double[] offset_x = new double[]{-.001,0,0};
pts_x.setOffset(offset_x);
Double scale_x = new Double(10);
pts_x.setScale(.75*scale_x);
java.awt.Font f_x = new java.awt.Font("Arial Bold", Font.ITALIC, 100);
pts_x.setFont(f_x);
text_x.setAppearance(text_xAp);
geometryNode.addChild(text_x);
try {
FileOutputStream u3dFileOutputStream = new FileOutputStream(RESOURCE);
WriterU3D.write(new JrScene(geometryNode), u3dFileOutputStream);
u3dFileOutputStream.close();
} catch(Exception exception){
exception.printStackTrace();
}
new Main().createPdf (RESULT);
}
this is the image of the Point
this is the expected result

jLibSvm: How to set up parameters for a well formed train

I'm trying to use jLibSvm to train biometric data, all of the same type.
There are 5 classes of data tagged with strings.
I've tried either with a MultiClassModel or with a BinaryModel, but in both case, any prediction always returns the same result, even by changing the gamma value.
Below, my code for MultiClassModel:
public static <L,SparseVector> void train(Map<SparseVector,L> examples){
MultiClassificationSVM svm = new MultiClassificationSVM(new C_SVC());
ImmutableSvmParameterPoint.Builder builder = new ImmutableSvmParameterPoint.Builder();
builder.C = 1.0;
builder.kernel = new GaussianRBFKernel(0.001);
builder.eps = 0.1f;
ImmutableSvmParameter params = builder.build();
MutableMultiClassProblemImpl problem =
new MutableMultiClassProblemImpl(String.class, null,
examples.size(), new NoopScalingModel());
problem.examples = examples;
for( SparseVector v : examples.keySet() )
problem.exampleIds.put(v, problem.exampleIds.size());
model = svm.train(problem, params);
}
And BinaryModel:
public static <L> void train(List<SparseVector> exTrue, List<SparseVector> exFalse, String label){
C_SVC svm = new C_SVC();
ImmutableSvmParameterPoint.Builder builder = new ImmutableSvmParameterPoint.Builder();
builder.C = C;
builder.kernel = new GaussianRBFKernel(gamma);
builder.eps = 0.001f;
ImmutableSvmParameter params = builder.build();
MutableBinaryClassificationProblemImpl problem
= new MutableBinaryClassificationProblemImpl(String.class, exTrue.size()+exFalse.size());
for(SparseVector v : exTrue)
problem.addExample(v, label);
String inverse = new StringLabelInverter().invert(label);
for(SparseVector v : exFalse)
problem.addExample(v, inverse);
BinaryModel bm = svm.train(problem, params);
models.put(label, bm);
}

Processing2.1.1 nullPointerException when trying loadTable()

I'm getting a nullPointExeption when trying to loadTable.
here is my code.
String twitterFile = "output2.csv";
String twitterDataFile = twitterFile;
ArrayList<Twitter> tweets = new ArrayList();
void setup() {
size(1000, 600, P2D);
smooth();
Table twitterCSV = loadTable(twitterDataFile, "header, csv");
}
Any ideia on what could it be?
thanks a lot

Null pointer exception on StackedBarChart

I'm trying to display a StackedBarChart with Java FX (running 1.7.0_45)
I get the following
java.lang.NullPointerException
at javafx.scene.chart.StackedBarChart.getDataItem(StackedBarChart.java:500)
at javafx.scene.chart.StackedBarChart.updateAxisRange(StackedBarChart.java:390)
at javafx.scene.chart.XYChart.layoutChartChildren(XYChart.java:620)
at javafx.scene.chart.Chart$1.layoutChildren(Chart.java:84)
at javafx.scene.Parent.layout(Parent.java:1018)
My code is below
public StackedBarChart<String, Number> createTreeNbChart() {
String[] typeString = new String[TypeE.values().length];
for (int i = 0; i < typeString.length; i++) {
typeString[i] = TypeE.values()[i].toString();
}
final CategoryAxis xAxis = CategoryAxisBuilder
.create()
.label("Type")
.categories(
FXCollections.<String> observableArrayList(typeString))
.build();
final NumberAxis yAxis = NumberAxisBuilder.create().label("Nb").build();
List<Tree> didBurn = new ArrayList<Tree>();
List<Tree> didGive = new ArrayList<Tree>();
List<Tree> nothingYet = new ArrayList<Tree>();
this.organizeTreesInto(didBurn, didGive, nothingYet);
// Trees which did give
ArrayList<StackedBarChart.Data<String, Number>> giveDataList = new ArrayList<>();
for (TypeE type : TypeE.values()) {
giveDataList.add(new StackedBarChart.Data<String, Number>(
type.toString(), this.treesFromListWithType(didGive, type)
.size()));
}
StackedBarChart.Series<String, Number> didGiveSeries = new StackedBarChart.Series<String, Number>(
"ont donné",
FXCollections.observableArrayList(giveDataList));
// Trees which did burn
ArrayList<StackedBarChart.Data<String, Number>> didBurnDataList = new ArrayList<>();
for (TypeE type : TypeE.values()) {
didBurnDataList.add(new StackedBarChart.Data<String, Number>(type
.toString(), this.treesFromListWithType(didBurn, type)
.size()));
}
StackedBarChart.Series<String, Number> didBurnSeries = new StackedBarChart.Series<String, Number>(
"ont brûlé", FXCollections.observableArrayList(didBurnDataList));
// Trees with nothing yet
ArrayList<StackedBarChart.Data<String, Number>> nothingYetDataList = new ArrayList<>();
for (TypeE type : TypeE.values()) {
didBurnDataList.add(new StackedBarChart.Data<String, Number>(type
.toString(), this.treesFromListWithType(nothingYet, type)
.size()));
}
StackedBarChart.Series<String, Number> nothingYetSeries = new StackedBarChart.Series<String, Number>(
"les autres",
FXCollections.observableArrayList(nothingYetDataList));
ObservableList<StackedBarChart.Series<String, Number>> barChartData = FXCollections
.observableArrayList(didGiveSeries, didBurnSeries,
nothingYetSeries);
final StackedBarChart<String, Number> chart = new StackedBarChart<String, Number>(
xAxis, yAxis, barChartData);
return chart;
Everything looks OK to me.
The only thing is that for the moment, all my data lists are empty, therefore the series will be empty. Maybe the problem is linked to that ?
I found the problem.
It was actually a copy-paste mistake in the following code
// Trees with nothing yet
ArrayList<StackedBarChart.Data<String, Number>> nothingYetDataList = new ArrayList<>();
for (TypeE type : TypeE.values()) {
didBurnDataList.add(new StackedBarChart.Data<String, Number>(type
.toString(), this.treesFromListWithType(nothingYet, type)
.size()));
}
I was adding stuff in the didBurnDataList instead of the nothingYetDataList.
Therefore the nothingYetDataList was always empty.
I'm not sure this is a good reason to throw a NPE anyway, since one can think of a scenario where Series of a stacked bar chart can be empty !

How can I get html code from the web with vala(gtk)?

How can I get a html code from some site(e.g. www.google.com) using vala(gtk)? I am using Val(a)IDE for programming.
Here is my code if someone need it:
public class Main
{
public static int main (string[] args)
{
Gtk.init (ref args);
Gtk.Window window = new Gtk.Window (Gtk.WindowType.TOPLEVEL);
window.title = "First test app";
window.set_default_size (320, 420);
window.position = Gtk.WindowPosition.CENTER;
window.destroy.connect(Gtk.main_quit);
var buttonBack = new Gtk.Button.with_label ("<");
var buttonForward = new Gtk.Button.with_label (">");
var buttonRefresh = new Gtk.Button.with_label ("Refresh");
var buttonStop = new Gtk.Button.with_label ("Stop");
buttonBack.set_size_request (20, 40);
buttonForward.set_size_request (20, 40);
buttonRefresh.set_size_request (20, 40);
buttonStop.set_size_request (20, 40);
//window.add (buttonBack);
var label1 = new Gtk.Label ("There will be something! :)");
label1.set_size_request (320,380);
//window.add (label1);
var hbox1 = new Gtk.HBox (true, 0);
var vbox1 = new Gtk.VBox (false, 0);
//var html = new Gtk.Widget();
//var empty = new Gtk.Label ("");
//empty.set_size_request(300, 10);
hbox1.add (buttonBack);
hbox1.add (buttonForward);
hbox1.add (buttonRefresh);
hbox1.add (buttonStop);
//hbox1.add (empty);
vbox1.add (hbox1);
vbox1.add (label1);
window.add (vbox1);
window.show_all ();
Gtk.main ();
return 0;
}
}
Forget it, someone just give me an answer on ask ubuntu site.
The answer is:
Use the Vala GIO File open shown here http://live.gnome.org/Vala/GIOSamples
var web_page = File.new_for_uri ("http://live.gnome.org/Vala");

Resources