NSView -draw method called multiple times - cocoa

I have a NSScrollView with embedded NSClipView and NSView. Nothing extraordinary. But when I change NSScrollView.magnification to something bigger than small, NSView.draw(_ dirtyRect:NSRect) is called from somewhere more then one time.
For magnification = 0.2 -draw is called just one time:
refresh 20.0%
visible rect: (-2634.99999999952, -812.500000000788, 5769.99999999869, 2625.00000000089)
drawing... (-250.0, -500.0, 1000.0, 2000.0)
refresh = magnification * 100
visible rect: - taken from NSClipView.documentVisibleRect
drawing... - prints dirtyRect on the beginning of -draw method
for .magnification = 1.0 — six times:
refresh 100.0%
visible rect: (-327.0, 237.5, 1154.0, 525.0)
drawing... (0.0, 0.0, 750.0, 1024.0)
drawing... (-250.0, 0.0, 250.0, 1024.0)
drawing... (-250.0, -500.0, 250.0, 500.0)
drawing... (0.0, -500.0, 750.0, 500.0)
drawing... (-250.0, 1024.0, 250.0, 476.0)
drawing... (0.0, 1024.0, 750.0, 476.0)
for 2.0... hard to count:
refresh 200.0%
visible rect: (-38.5, 368.75, 577.0, 262.5)
drawing... (384.0, 256.0, 128.0, 128.0)
drawing... (256.0, 512.0, 128.0, 128.0)
drawing... (0.0, 256.0, 128.0, 128.0)
drawing... (512.0, 384.0, 128.0, 128.0)
drawing... (384.0, 512.0, 128.0, 128.0)
drawing... (128.0, 256.0, 128.0, 128.0)
drawing... (-128.0, 384.0, 128.0, 128.0)
drawing... (0.0, 512.0, 128.0, 128.0)
drawing... (256.0, 384.0, 128.0, 128.0)
drawing... (128.0, 512.0, 128.0, 128.0)
drawing... (512.0, 256.0, 128.0, 128.0)
drawing... (384.0, 384.0, 128.0, 128.0)
drawing... (-128.0, 512.0, 128.0, 128.0)
drawing... (0.0, 384.0, 128.0, 128.0)
drawing... (512.0, 512.0, 128.0, 128.0)
drawing... (256.0, 256.0, 128.0, 128.0)
drawing... (128.0, 384.0, 128.0, 128.0)
drawing... (-128.0, 256.0, 128.0, 128.0)
drawing... (-128.0, 128.0, 128.0, 128.0)
drawing... (0.0, 128.0, 128.0, 128.0)
drawing... (128.0, 128.0, 128.0, 128.0)
drawing... (256.0, 128.0, 128.0, 128.0)
drawing... (384.0, 128.0, 128.0, 128.0)
drawing... (512.0, 128.0, 128.0, 128.0)
drawing... (-128.0, 640.0, 128.0, 128.0)
drawing... (0.0, 640.0, 128.0, 128.0)
drawing... (128.0, 640.0, 128.0, 128.0)
drawing... (256.0, 640.0, 128.0, 128.0)
drawing... (384.0, 640.0, 128.0, 128.0)
drawing... (512.0, 640.0, 128.0, 128.0)
drawing... (-250.0, 128.0, 122.0, 128.0)
drawing... (-250.0, 256.0, 122.0, 128.0)
drawing... (-250.0, 384.0, 122.0, 128.0)
drawing... (-250.0, 512.0, 122.0, 128.0)
drawing... (-250.0, 640.0, 122.0, 128.0)
drawing... (640.0, 128.0, 110.0, 128.0)
drawing... (640.0, 256.0, 110.0, 128.0)
drawing... (640.0, 384.0, 110.0, 128.0)
drawing... (640.0, 512.0, 110.0, 128.0)
drawing... (640.0, 640.0, 110.0, 128.0)
drawing... (-250.0, 0.0, 122.0, 128.0)
drawing... (-128.0, 0.0, 128.0, 128.0)
drawing... (0.0, 0.0, 128.0, 128.0)
drawing... (128.0, 0.0, 128.0, 128.0)
drawing... (256.0, 0.0, 128.0, 128.0)
drawing... (384.0, 0.0, 128.0, 128.0)
drawing... (512.0, 0.0, 128.0, 128.0)
drawing... (640.0, 0.0, 110.0, 128.0)
drawing... (-250.0, 768.0, 122.0, 128.0)
drawing... (-128.0, 768.0, 128.0, 128.0)
drawing... (0.0, 768.0, 128.0, 128.0)
drawing... (128.0, 768.0, 128.0, 128.0)
drawing... (256.0, 768.0, 128.0, 128.0)
drawing... (384.0, 768.0, 128.0, 128.0)
drawing... (512.0, 768.0, 128.0, 128.0)
drawing... (640.0, 768.0, 110.0, 128.0)
drawing... (-250.0, -128.0, 122.0, 128.0)
drawing... (-128.0, -128.0, 128.0, 128.0)
drawing... (0.0, -128.0, 128.0, 128.0)
drawing... (128.0, -128.0, 128.0, 128.0)
drawing... (256.0, -128.0, 128.0, 128.0)
drawing... (384.0, -128.0, 128.0, 128.0)
drawing... (512.0, -128.0, 128.0, 128.0)
drawing... (640.0, -128.0, 110.0, 128.0)
drawing... (-250.0, 896.0, 122.0, 128.0)
drawing... (-128.0, 896.0, 128.0, 128.0)
drawing... (0.0, 896.0, 128.0, 128.0)
drawing... (128.0, 896.0, 128.0, 128.0)
drawing... (256.0, 896.0, 128.0, 128.0)
drawing... (384.0, 896.0, 128.0, 128.0)
drawing... (512.0, 896.0, 128.0, 128.0)
drawing... (640.0, 896.0, 110.0, 128.0)
drawing... (-250.0, -256.0, 122.0, 128.0)
drawing... (-128.0, -256.0, 128.0, 128.0)
drawing... (0.0, -256.0, 128.0, 128.0)
drawing... (128.0, -256.0, 128.0, 128.0)
drawing... (256.0, -256.0, 128.0, 128.0)
drawing... (384.0, -256.0, 128.0, 128.0)
drawing... (512.0, -256.0, 128.0, 128.0)
drawing... (640.0, -256.0, 110.0, 128.0)
drawing... (-250.0, 1024.0, 122.0, 128.0)
drawing... (-128.0, 1024.0, 128.0, 128.0)
drawing... (0.0, 1024.0, 128.0, 128.0)
drawing... (128.0, 1024.0, 128.0, 128.0)
drawing... (256.0, 1024.0, 128.0, 128.0)
drawing... (384.0, 1024.0, 128.0, 128.0)
drawing... (512.0, 1024.0, 128.0, 128.0)
drawing... (640.0, 1024.0, 110.0, 128.0)
drawing... (-250.0, -384.0, 122.0, 128.0)
drawing... (-128.0, -384.0, 128.0, 128.0)
drawing... (0.0, -384.0, 128.0, 128.0)
drawing... (128.0, -384.0, 128.0, 128.0)
drawing... (256.0, -384.0, 128.0, 128.0)
drawing... (384.0, -384.0, 128.0, 128.0)
drawing... (512.0, -384.0, 128.0, 128.0)
drawing... (640.0, -384.0, 110.0, 128.0)
drawing... (-250.0, 1152.0, 122.0, 128.0)
drawing... (-128.0, 1152.0, 128.0, 128.0)
drawing... (0.0, 1152.0, 128.0, 128.0)
drawing... (128.0, 1152.0, 128.0, 128.0)
drawing... (256.0, 1152.0, 128.0, 128.0)
drawing... (384.0, 1152.0, 128.0, 128.0)
drawing... (512.0, 1152.0, 128.0, 128.0)
drawing... (640.0, 1152.0, 110.0, 128.0)
If I will set magnification = 10.0, (1000%) -draw is called many, many, many times.
Is it some way to avoid it?
I check all -needsDisplay in my app, and I'm sure they're not responsible for this behaviour.

Related

'vertexColors' parameter is undefined?

const material = new THREE.LineBasicMaterial({
vertexColors: THREE.VertexColors,
transparent: true,
side: THREE.DoubleSide,
})
why?
.vertexColors can either be true or false, nothing else. THREE.VertexColors does not exist, so it comes out as undefined.
https://threejs.org/docs/index.html#api/en/materials/Material.vertexColors
Parameters in Material vertexColors are boolean, true or false.
so if you have specified point color in float array then it can define boolean value (true or false), I will give a little example like this, and this is what I did it worked.
const myGeo = new THREE.BufferGeometry();
let vertices = new Float32Array([
-1.0, -1.0, 1.0, // 0
1.0, 1.0, 1.0, // 1
-1.0, 1.0, 1.0, // 2
1.0, -1.0, 1.0, // 3
-1.0, -1.0, -1.0, // 4
1.0, 1.0, -1.0, // 5
-1.0, 1.0, -1.0, // 6
1.0, -1.0, -1.0, // 7
]);
let colors = new Float32Array([
1.0, 0.0, 0.0, // Vertex 0 (Red)
1.0, 0.0, 0.0, // Vertex 1 (Red)
1.0, 1.0, 0.0, // Vertex 2 (Yellow)
1.0, 1.0, 0.0, // Vertex 3 (Yellow)
0.0, 1.0, 0.0, // Vertex 4 (Green)
0.0, 1.0, 0.0, // Vertex 5 (Green)
0.0, 0.0, 1.0, // Vertex 6 (Blue)
0.0, 0.0, 1.0, // Vertex 7 (Blue)
]);
myGeo.setAttribute('position', new THREE.BufferAttribute( vertices, 3 ));
myGeo.setAttribute('color', new THREE.BufferAttribute( colors, 3 ));
myGeo.setIndex([.....]);
const material= new THREE.MeshBasicMaterial({ vertexColors:true, side: THREE.DoubleSide, });
let mesh = new THREE.Mesh(myGeo, material)
scene.add(mesh);

Gradient Stop Locations at Variable Values SwiftUI

I'm trying to make a gradient composed of 4 stops in SwiftUI. I'd like the middle two to be anchored to the bottom of a specific stack. Something like this:
Imgur Link of what I'm trying to do
Here's the gradient code I currently have:
LinearGradient(gradient: Gradient(stops: [
//top Gradient.Stop(color: Color(hue: 0.0, saturation: 0.0, brightness: 0.0, opacity: 0.0), location: 0.0),
//variable1 Gradient.Stop(color: Color(hue: 0.0, saturation: 0.0, brightness: 0.0, opacity: 0.3), location: 0.30 //<-Variable),
//variable2 Gradient.Stop(color: Color(hue: 0.0, saturation: 0.0, brightness: 0.0, opacity: 1.0), location: 0.35 //<-Variable),
//bottom Gradient.Stop(color: Color(hue: 0.1, saturation: 1.0, brightness: 0.0, opacity: 1.0), location: 1.0)),
startPoint: UnitPoint.top, endPoint: UnitPoint.bottom)
You can simply use the frame size of the "Content Box" to determine at what position to place the gradient stop. I did this by just having a variable called frameHeight.
import SwiftUI
struct ContentView: View {
let screenWidth = UIScreen.main.bounds.width
let screenHeight = UIScreen.main.bounds.height
var frameHeight = 200
var body: some View {
let gradient = Gradient(stops: [Gradient.Stop(color: .blue, location: 0.0),
Gradient.Stop(color: .white, location: CGFloat(frameHeight)/screenHeight),
Gradient.Stop(color: .black, location: CGFloat(frameHeight)/screenHeight + 0.05),
Gradient.Stop(color: .black, location: 1.0)])
VStack{
//Content Box view of frameHeight
VStack {
Text("Content Box")
}.frame(width: screenWidth, height: CGFloat(frameHeight))
Spacer()
}.frame(width: screenWidth, height: screenHeight)
.background(LinearGradient(gradient: gradient, startPoint: UnitPoint.top, endPoint: UnitPoint.bottom))
.edgesIgnoringSafeArea(.all)
}
}

Solution of Jsprit is not correct if shipments have multiple size of dimension

I am new to Jsprit. I tried to use multiple size of dimension in my shipment list. For example, some shipments I added size of dimension with WHEELCHAIRSPACE_INDEX and some shipments I use PASSENGERSEATS_INDEX in my createJob(). However the output seem like wrong.
public class Test {
static int WHEELCHAIRSPACE_INDEX = 0;
static int PASSENGERSEATS_INDEX = 1;
private VehicleType vehicleType_wheelchair;
private VehicleType vehicleType_solelypassenger;
private VehicleImpl vehicle1,vehicle1_2,vehicle2,vehicle2_2;
private VehicleRoutingProblem.Builder vrpBuilder;
private HardRouteConstraint wheelchair_bus_passenger_pickup_constraint;
private VehicleRoutingAlgorithm algorithm;
private VehicleRoutingProblem problem;
private VehicleRoutingTransportCosts costMatrix;
private static final String FILENAME = "C:\\Users\\admin\\Desktop\\test.txt";
public static void main(String[] args) {
// TODO Auto-generated method stub
Examples.createOutputFolder();
Test test = new Test();
test.createVehicleType();
test.createVehicle();
test.createJob();
test.createConstraint();
test.createProblem();
test.searchSolution();
}
private void searchSolution() {
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);
SolutionPrinter.print(problem, bestSolution, SolutionPrinter.Print.VERBOSE);
Plotter problemPlotter = new Plotter(problem);
problemPlotter.plotShipments(true);
problemPlotter.setLabel(Plotter.Label.SIZE);
problemPlotter.plot("output/transportOfDisabledPeopleExample_problem.png", "disabled people tp");
Plotter solutionPlotter = new Plotter(problem, Solutions.bestOf(solutions));
solutionPlotter.plotShipments(true);
solutionPlotter.setLabel(Plotter.Label.SIZE);
solutionPlotter.plot("output/transportOfDisabledPeopleExample_solution.png", "disabled people tp");
}
private void createProblem() {
StateManager stateManager = new StateManager(problem);
ConstraintManager constraintManager = new ConstraintManager(problem, stateManager);
constraintManager.addConstraint(wheelchair_bus_passenger_pickup_constraint);
algorithm = Jsprit.Builder.newInstance(problem).setStateAndConstraintManager(stateManager,constraintManager).buildAlgorithm();
algorithm.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100));
}
private void createConstraint() {
wheelchair_bus_passenger_pickup_constraint = new HardRouteConstraint() {
#Override
public boolean fulfilled(JobInsertionContext insertionContext) {
return true;
}
};
}
private void createJob() {
com.graphhopper.jsprit.core.problem.job.Shipment.Builder builder1 = Shipment.Builder.newInstance("1");
builder1.addSizeDimension(WHEELCHAIRSPACE_INDEX, 1);
builder1.setPickupLocation(Location.newInstance("1a"));
builder1.setDeliveryLocation(Location.newInstance("1b"));
builder1.setDeliveryServiceTime(0);
Shipment shipment1 = builder1.build();
com.graphhopper.jsprit.core.problem.job.Shipment.Builder builder2 = Shipment.Builder.newInstance("2");
builder2.addSizeDimension(PASSENGERSEATS_INDEX, 1);
builder2.setPickupLocation(Location.newInstance("2a"));
builder2.setDeliveryLocation(Location.newInstance("2b"));
builder2.setDeliveryServiceTime(0);
Shipment shipment2 = builder2.build();
com.graphhopper.jsprit.core.problem.job.Shipment.Builder builder3 = Shipment.Builder.newInstance("3");
builder3.addSizeDimension(WHEELCHAIRSPACE_INDEX, 1);
builder3.setPickupLocation(Location.newInstance("3a"));
builder3.setDeliveryLocation(Location.newInstance("3b"));
builder3.setDeliveryServiceTime(0);
Shipment shipment3 = builder3.build();
com.graphhopper.jsprit.core.problem.job.Shipment.Builder builder4 = Shipment.Builder.newInstance("4");
builder4.addSizeDimension(PASSENGERSEATS_INDEX, 1);
builder4.setPickupLocation(Location.newInstance("4a"));
builder4.setDeliveryLocation(Location.newInstance("4b"));
builder4.setDeliveryServiceTime(0);
Shipment shipment4 = builder4.build();
com.graphhopper.jsprit.core.problem.job.Shipment.Builder builder5 = Shipment.Builder.newInstance("5");
builder5.addSizeDimension(WHEELCHAIRSPACE_INDEX, 1);
builder5.setPickupLocation(Location.newInstance("5a"));
builder5.setDeliveryLocation(Location.newInstance("5b"));
builder5.setDeliveryServiceTime(0);
Shipment shipment5 = builder5.build();
setTransportCost();
vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
vrpBuilder.addVehicle(vehicle1);
vrpBuilder.addVehicle(vehicle2);
vrpBuilder.addVehicle(vehicle1_2);
vrpBuilder.addVehicle(vehicle2_2);
vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4);
vrpBuilder.addJob(shipment5);
vrpBuilder.setFleetSize(FleetSize.FINITE);
vrpBuilder.setRoutingCost(costMatrix);
problem = vrpBuilder.build();
}
private void setTransportCost() {
// TODO Auto-generated method stub
VehicleRoutingTransportCostsMatrix.Builder costMatrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true);
costMatrixBuilder.addTransportTime("0", "0", 0.0);
costMatrixBuilder.addTransportTime("0", "1a", 2.0);
costMatrixBuilder.addTransportTime("0", "1b", 3.3);
costMatrixBuilder.addTransportTime("0", "2a", 2.0);
costMatrixBuilder.addTransportTime("0", "2b", 4.3);
costMatrixBuilder.addTransportTime("0", "3a", 3.5);
costMatrixBuilder.addTransportTime("0", "3b", 3.0);
costMatrixBuilder.addTransportTime("0", "4a", 1.5);
costMatrixBuilder.addTransportTime("0", "4b", 2.7);
costMatrixBuilder.addTransportTime("0", "5a", 1.2);
costMatrixBuilder.addTransportTime("0", "5b", 3.5);
costMatrixBuilder.addTransportTime("1a", "0", 2.0);
costMatrixBuilder.addTransportTime("1a", "1a", 0.0);
costMatrixBuilder.addTransportTime("1a", "1b", 2.5);
costMatrixBuilder.addTransportTime("1a", "2a", 2.3);
costMatrixBuilder.addTransportTime("1a", "2b", 4.4);
costMatrixBuilder.addTransportTime("1a", "3a", 4.0);
costMatrixBuilder.addTransportTime("1a", "3b", 4.0);
costMatrixBuilder.addTransportTime("1a", "4a", 2.3);
costMatrixBuilder.addTransportTime("1a", "4b", 4.5);
costMatrixBuilder.addTransportTime("1a", "5a", 3.2);
costMatrixBuilder.addTransportTime("1a", "5b", 1.5);
costMatrixBuilder.addTransportTime("1b", "0", 3.3);
costMatrixBuilder.addTransportTime("1b", "1a", 2.5);
costMatrixBuilder.addTransportTime("1b", "1b", 0.0);
costMatrixBuilder.addTransportTime("1b", "2a", 1.7);
costMatrixBuilder.addTransportTime("1b", "2b", 2.2);
costMatrixBuilder.addTransportTime("1b", "3a", 2.5);
costMatrixBuilder.addTransportTime("1b", "3b", 3.4);
costMatrixBuilder.addTransportTime("1b", "4a", 4.5);
costMatrixBuilder.addTransportTime("1b", "4b", 5.0);
costMatrixBuilder.addTransportTime("1b", "5a", 4.5);
costMatrixBuilder.addTransportTime("1b", "5b", 2.2);
costMatrixBuilder.addTransportTime("2a", "0", 2.0);
costMatrixBuilder.addTransportTime("2a", "1a", 2.3);
costMatrixBuilder.addTransportTime("2a", "1b", 1.7);
costMatrixBuilder.addTransportTime("2a", "2a", 0.0);
costMatrixBuilder.addTransportTime("2a", "2b", 2.3);
costMatrixBuilder.addTransportTime("2a", "3a", 1.7);
costMatrixBuilder.addTransportTime("2a", "3b", 1.8);
costMatrixBuilder.addTransportTime("2a", "4a", 3.3);
costMatrixBuilder.addTransportTime("2a", "4b", 3.2);
costMatrixBuilder.addTransportTime("2a", "5a", 3.0);
costMatrixBuilder.addTransportTime("2a", "5b", 2.9);
costMatrixBuilder.addTransportTime("2b", "0", 4.3);
costMatrixBuilder.addTransportTime("2b", "1a", 4.4);
costMatrixBuilder.addTransportTime("2b", "1b", 2.2);
costMatrixBuilder.addTransportTime("2b", "2a", 2.3);
costMatrixBuilder.addTransportTime("2b", "2b", 0.0);
costMatrixBuilder.addTransportTime("2b", "3a", 1.2);
costMatrixBuilder.addTransportTime("2b", "3b", 2.8);
costMatrixBuilder.addTransportTime("2b", "4a", 5.7);
costMatrixBuilder.addTransportTime("2b", "4b", 4.5);
costMatrixBuilder.addTransportTime("2b", "5a", 5.2);
costMatrixBuilder.addTransportTime("2b", "5b", 4.3);
costMatrixBuilder.addTransportTime("3a", "0", 3.5);
costMatrixBuilder.addTransportTime("3a", "1a", 4.0);
costMatrixBuilder.addTransportTime("3a", "1b", 2.5);
costMatrixBuilder.addTransportTime("3a", "2a", 1.7);
costMatrixBuilder.addTransportTime("3a", "2b", 1.2);
costMatrixBuilder.addTransportTime("3a", "3a", 0.0);
costMatrixBuilder.addTransportTime("3a", "3b", 1.5);
costMatrixBuilder.addTransportTime("3a", "4a", 5.0);
costMatrixBuilder.addTransportTime("3a", "4b", 3.3);
costMatrixBuilder.addTransportTime("3a", "5a", 4.2);
costMatrixBuilder.addTransportTime("3a", "5b", 4.3);
costMatrixBuilder.addTransportTime("3b", "0", 3.0);
costMatrixBuilder.addTransportTime("3b", "1a", 4.0);
costMatrixBuilder.addTransportTime("3b", "1b", 3.4);
costMatrixBuilder.addTransportTime("3b", "2a", 1.8);
costMatrixBuilder.addTransportTime("3b", "2b", 2.8);
costMatrixBuilder.addTransportTime("3b", "3a", 1.5);
costMatrixBuilder.addTransportTime("3b", "3b", 0.0);
costMatrixBuilder.addTransportTime("3b", "4a", 4.3);
costMatrixBuilder.addTransportTime("3b", "4b", 1.8);
costMatrixBuilder.addTransportTime("3b", "5a", 2.8);
costMatrixBuilder.addTransportTime("3b", "5b", 5.0);
costMatrixBuilder.addTransportTime("4a", "0", 1.5);
costMatrixBuilder.addTransportTime("4a", "1a", 2.3);
costMatrixBuilder.addTransportTime("4a", "1b", 4.5);
costMatrixBuilder.addTransportTime("4a", "2a", 3.3);
costMatrixBuilder.addTransportTime("4a", "2b", 5.7);
costMatrixBuilder.addTransportTime("4a", "3a", 5.0);
costMatrixBuilder.addTransportTime("4a", "3b", 4.3);
costMatrixBuilder.addTransportTime("4a", "4a", 0.0);
costMatrixBuilder.addTransportTime("4a", "4b", 3.6);
costMatrixBuilder.addTransportTime("4a", "5a", 1.7);
costMatrixBuilder.addTransportTime("4a", "5b", 3.8);
costMatrixBuilder.addTransportTime("4b", "0", 2.7);
costMatrixBuilder.addTransportTime("4b", "1a", 4.5);
costMatrixBuilder.addTransportTime("4b", "1b", 5.0);
costMatrixBuilder.addTransportTime("4b", "2a", 3.2);
costMatrixBuilder.addTransportTime("4b", "2b", 4.5);
costMatrixBuilder.addTransportTime("4b", "3a", 3.3);
costMatrixBuilder.addTransportTime("4b", "3b", 1.8);
costMatrixBuilder.addTransportTime("4b", "4a", 3.6);
costMatrixBuilder.addTransportTime("4b", "4b", 0.0);
costMatrixBuilder.addTransportTime("4b", "5a", 1.9);
costMatrixBuilder.addTransportTime("4b", "5b", 5.7);
costMatrixBuilder.addTransportTime("5a", "0", 1.2);
costMatrixBuilder.addTransportTime("5a", "1a", 3.2);
costMatrixBuilder.addTransportTime("5a", "1b", 4.5);
costMatrixBuilder.addTransportTime("5a", "2a", 3.0);
costMatrixBuilder.addTransportTime("5a", "2b", 5.2);
costMatrixBuilder.addTransportTime("5a", "3a", 4.2);
costMatrixBuilder.addTransportTime("5a", "3b", 2.8);
costMatrixBuilder.addTransportTime("5a", "4a", 1.7);
costMatrixBuilder.addTransportTime("5a", "4b", 1.9);
costMatrixBuilder.addTransportTime("5a", "5a", 0.0);
costMatrixBuilder.addTransportTime("5a", "5b", 4.7);
costMatrixBuilder.addTransportTime("5b", "0", 3.5);
costMatrixBuilder.addTransportTime("5b", "1a", 1.5);
costMatrixBuilder.addTransportTime("5b", "1b", 2.2);
costMatrixBuilder.addTransportTime("5b", "2a", 2.9);
costMatrixBuilder.addTransportTime("5b", "2b", 4.3);
costMatrixBuilder.addTransportTime("5b", "3a", 4.3);
costMatrixBuilder.addTransportTime("5b", "3b", 5.0);
costMatrixBuilder.addTransportTime("5b", "4a", 3.8);
costMatrixBuilder.addTransportTime("5b", "4b", 5.7);
costMatrixBuilder.addTransportTime("5b", "5a", 4.7);
costMatrixBuilder.addTransportTime("5b", "5b", 0.0);
costMatrix = costMatrixBuilder.build();
}
private void createVehicle() {
Builder vehicleBuilder1 = VehicleImpl.Builder.newInstance("wheelchair_bus");
vehicleBuilder1.setStartLocation(Location.newInstance("0")).setEndLocation(Location.newInstance("0"));
vehicleBuilder1.setType(vehicleType_wheelchair);
vehicleBuilder1.setEarliestStart(0);
vehicleBuilder1.setLatestArrival(10);
vehicle1 = vehicleBuilder1.build();
Builder vehicleBuilder1_2 = VehicleImpl.Builder.newInstance("wheelchair_bus_2");
vehicleBuilder1_2.setStartLocation(Location.newInstance("0")).setEndLocation(Location.newInstance("0"));
vehicleBuilder1_2.setType(vehicleType_wheelchair);
vehicleBuilder1_2.setEarliestStart(0);
vehicleBuilder1_2.setLatestArrival(10);
vehicle1_2 = vehicleBuilder1_2.build();
Builder vehicleBuilder2 = VehicleImpl.Builder.newInstance("passenger_bus");
vehicleBuilder2.setStartLocation(Location.newInstance("0")).setEndLocation(Location.newInstance("0"));
vehicleBuilder2.setType(vehicleType_solelypassenger);
vehicleBuilder2.setEarliestStart(0);
vehicleBuilder2.setLatestArrival(10);
vehicle2 = vehicleBuilder2.build();
Builder vehicleBuilder2_2 = VehicleImpl.Builder.newInstance("passenger_bus_2");
vehicleBuilder2_2.setStartLocation(Location.newInstance("0")).setEndLocation(Location.newInstance("0"));
vehicleBuilder2_2.setType(vehicleType_solelypassenger);
vehicleBuilder2_2.setEarliestStart(0);
vehicleBuilder2_2.setLatestArrival(10);
vehicle2_2 = vehicleBuilder2_2.build();
}
private void createVehicleType() {
VehicleTypeImpl.Builder wheelChairTypeBuilder = VehicleTypeImpl.Builder.newInstance("wheelChairBusType");
wheelChairTypeBuilder.addCapacityDimension(WHEELCHAIRSPACE_INDEX, 2);
wheelChairTypeBuilder.addCapacityDimension(PASSENGERSEATS_INDEX, 4);
//wheelChairTypeBuilder.setCostPerDistance(1);
wheelChairTypeBuilder.setCostPerTransportTime(2);
vehicleType_wheelchair = wheelChairTypeBuilder.build();
VehicleTypeImpl.Builder soleyPassengerTypeBuilder = VehicleTypeImpl.Builder.newInstance("passengerBusType");
soleyPassengerTypeBuilder.addCapacityDimension(PASSENGERSEATS_INDEX, 6);
//soleyPassengerTypeBuilder.setCostPerDistance(1);
soleyPassengerTypeBuilder.setCostPerTransportTime(2);
vehicleType_solelypassenger = soleyPassengerTypeBuilder.build();
}
private static Location loc(Coordinate coordinate) {
return Location.Builder.newInstance().setCoordinate(coordinate).build();
}
}
This is the output
Shipment 1 and shipment 5 is not assigned to job list. However, if I change add all size of dimension to PASSENGERSEATS_INDEX then all jobs are assigned correctly. Does that mean that the algorithm is not support multiple size of dimension?
I found that there is a solution which assign 4 jobs when I stepped into the code in debugging mode. However,it is consider as not accepted solution in Jsprit. From logically thinking, this solution should be the correct solution because it minimize the unassigned job (compare to original solution only assign 3 job).
When you built your cost matrix, you only specified travel time, not distances.
By default, the cost of an unassigned job depends on the the (maximum) distances between the pickup and delivery locations. Since distances aren't set, there is no penalty for unassigned jobs.
An easy solution would be to add some reasonable distance metric when you build the cost matrix:
private void setTransportCost() {
VehicleRoutingTransportCostsMatrix.Builder costMatrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true);
String[] locationIds = new String[] {"0", "1a", "1b", "2a", "2b", "3a", "3b", "4a", "4b", "5a", "5b"};
for (String l1: locationIds) {
for (String l2: locationIds) {
if (!l1.equals(l2)) {
costMatrixBuilder.addTransportDistance(l1, l2, 5);
}
}
}
// ... on with original implementation ...

UIButton animation title position changed unexpected

UIButton animation title position changed suddenly (jumped to the left), I want to keep the title in the button center nearby always.
You can see the button title ("Login In") jumped to the left unexpected, which should be optimized.
Here is the code:
UIView.animate(withDuration: 1.5, delay: 0.0, usingSpringWithDamping: 0.2, initialSpringVelocity: 0.0, options: [], animations: {
self.loginButton.bounds.size.width -= 80.0
}){ (yes) in }
UIView.animate(withDuration: 0.33, delay: 0.0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.0, options: [], animations: {
self.loginButton.center.y -= 60.0
self.loginButton.backgroundColor = UIColor(red: 0.63, green: 0.84, blue: 0.35, alpha: 1.0)
self.spinner.center = CGPoint(x: -20, y: -16)
self.spinner.alpha = 0.0
}){ (yes) in }
Here is the code I tried , which does not work too.
UIView.animate(withDuration: 0.3, delay: 0.2, options: [], animations: {
self.loginButton.backgroundColor = UIColor(red: 0.63, green: 0.84, blue: 0.35, alpha: 1.0)
self.loginButton.bounds.size.width -= 80.0
self.loginButton.center.y -= 60.0
self.spinner.frame.origin = CGPoint(x: -20, y: 16)
self.spinner.alpha = 0.0
}) { (isOK) in }
PS:
I add the login button through storyboard , as the following image
And the code relevant is here
Add line in animation function
UIView.animate(withDuration: 1, delay: 0.2, options: [], animations: {
//Your code for animation
.
.
.
//Add this line
self.view.layoutIfNeeded()
}) { (isOK) in }
Note
Use Auto Layout for all device support and easy to animation

WebGL/GLSL vertex shader collapses 9 points into single point when I set x coord of gl_Position to zero

I do not understand why the following two shaders produce different results when I render a vertex buffer with x coordinates equal to zero:
First:
attribute vec3 position;
void main() {
gl_Position = vec4(position.x, position.y, 0.0, 1.0);
}
Second:
attribute vec3 position;
void main() {
gl_Position = vec4(0.0, position.y, 0.0, 1.0);
}
The result of the first is a line of nine dots. The result of the second is a single dot.
I'm drawing the following vertex array as GL_POINTS:
0.0, -1.00, 0.0,
0.0, -0.75, 0.0,
0.0, -0.50, 0.0,
0.0, -0.25, 0.0,
0.0, 0.00, 0.0,
0.0, 0.25, 0.0,
0.0, 0.50, 0.0,
0.0, 0.75, 0.0,
0.0, 1.00, 0.0
Here's the VBO preparation calls:
var a = new Float32Array([
0.0, -1.00, 0.0,
0.0, -0.75, 0.0,
0.0, -0.50, 0.0,
0.0, -0.25, 0.0,
0.0, 0.00, 0.0,
0.0, 0.25, 0.0,
0.0, 0.50, 0.0,
0.0, 0.75, 0.0,
0.0, 1.00, 0.0
]);
gl.bindBuffer(gl.ARRAY_BUFFER, b);
gl.bufferData(gl.ARRAY_BUFFER, a.byteLength, gl.STATIC_DRAW);
gl.bufferSubData(gl.ARRAY_BUFFER, 0, a);
Here's the draw calls:
gl.bindBuffer(gl.ARRAY_BUFFER, b);
gl.vertexAttribPointer(p.position, 3, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(p.position);
gl.drawArrays(gl.POINTS, 0, 9);
That is a known problem (sorry, no link for now).
Basically, GLSL compiler thinks that attribute 'position' is not used, because the first component of it is not used. To check this try the following test:
gl_Position = vec4(0.0, position.y, 0.0, 1.0) + position.x*0.001;
Once you confirm the bug, you can either update you video driver or use an obvious workaround.

Resources