I'm using Gurobi in Python. I'm iterating over a set of nodes and at each iteration, I'm adding a constraint to solve. After solving, it produces the Gurobi log as follows:
Optimize a model with 6 rows, 36 columns and 41 nonzeros
Variable types: 0 continuous, 36 integer (36 binary)
Coefficient statistics:
Matrix range [1e+00, 1e+00]
Objective range [2e+01, 9e+01]
Bounds range [1e+00, 1e+00]
RHS range [2e+00, 2e+00]
MIP start did not produce a new incumbent solution
MIP start violates constraint R5 by 2.000000000
Found heuristic solution: objective 347.281
Presolve removed 2 rows and 21 columns
Presolve time: 0.00s
Presolved: 4 rows, 15 columns, 27 nonzeros
Found heuristic solution: objective 336.2791955
Variable types: 0 continuous, 15 integer (15 binary)
Root relaxation: objective 3.043757e+02, 6 iterations, 0.00 seconds
Nodes | Current Node | Objective Bounds | Work
Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
* 0 0 0 304.3757488 304.37575 0.00% - 0s
Explored 0 nodes (6 simplex iterations) in 0.02 seconds
Thread count was 4 (of 4 available processors)
Solution count 3: 304.376 336.279 339.43
Optimal solution found (tolerance 1.00e-04)
Best objective 3.043757488224e+02, best bound 3.043757488224e+02, gap 0.0000%
But after a certain iteration, my answer is not what I'm expecting. So I wish to print all my model details (objective function, constraints etc) in the Gurobi log at every iteration.How can I do that?
But model.write() prints the objective function and the constraint that we have coded.
Minimize
0 x(0,0) + 75.47184905645283 x(0,1) + 57.55866572463264 x(0,2)
+ 33.97057550292606 x(0,3) + 23.3238075793812 x(0,4)
+ 40.80441152620633 x(0,5) + 75.47184905645283 x(1,0) + 0 x(1,1)
+ 32.7566787083184 x(1,2) + 90.60905032059435 x(1,3)
+ 55.71355310873648 x(1,4) + 40.60788100849391 x(1,5)
+ 57.55866572463264 x(2,0) + 32.7566787083184 x(2,1) + 0 x(2,2)
+ 83.36066218546971 x(2,3) + 46.57252408878007 x(2,4)
+ 41.4004830889689 x(2,5) + 33.97057550292606 x(3,0)
+ 90.60905032059435 x(3,1) + 83.36066218546971 x(3,2) + 0 x(3,3)
+ 37.12142238654117 x(3,4) + 50.00999900019995 x(3,5)
+ 23.3238075793812 x(4,0) + 55.71355310873648 x(4,1)
+ 46.57252408878007 x(4,2) + 37.12142238654117 x(4,3) + 0 x(4,4)
+ 17.69180601295413 x(4,5) + 40.80441152620633 x(5,0)
+ 40.60788100849391 x(5,1) + 41.4004830889689 x(5,2)
+ 50.00999900019995 x(5,3) + 17.69180601295413 x(5,4) + 0 x(5,5)
Subject To
R0: x(0,1) + x(0,2) + x(0,3) + x(0,4) + x(0,5) >= 2
R1: x(1,0) + x(1,2) + x(1,3) + x(1,4) + x(1,5) >= 2
R2: x(1,0) + x(1,3) + x(1,4) + x(2,0) + x(2,3) + x(2,4) + x(5,0) +
x(5,3)+ x(5,4) >= 2
R3: x(3,0) + x(3,1) + x(3,2) + x(3,4) + x(3,5) >= 2
R4: x(0,1) + x(0,2) + x(0,5) + x(3,1) + x(3,2) + x(3,5) + x(4,1) +
x(4,2)+ x(4,5) >= 2
R5: x(0,1) + x(0,2) + x(3,1) + x(3,2) + x(4,1) + x(4,2) + x(5,1) +
x(5,2)>= 2
Bounds
Binaries
x(0,0) x(0,1) x(0,2) x(0,3) x(0,4) x(0,5) x(1,0) x(1,1) x(1,2) x(1,3)
x(1,4) x(1,5) x(2,0) x(2,1) x(2,2) x(2,3) x(2,4) x(2,5) x(3,0) x(3,1)
x(3,2) x(3,3) x(3,4) x(3,5) x(4,0) x(4,1) x(4,2) x(4,3) x(4,4) x(4,5)
x(5,0) x(5,1) x(5,2) x(5,3) x(5,4) x(5,5)
End
What I need in this is to know what is happening at each iteration. That's because one iteration gives me another false answer and so I want to check whether any redundant constraint is adding into the model when solving.
In other words, does "Gurobi callbacks" allow us to access all information that is available in the model? What will it produce?
In other words, does "Gurobi callbacks" allow us to access all
information that is available in the model? What will it produce?
No, you cannot print constraints generated in a callback function.
Most likely, the issue is one of the following:
You are calling the wrong function inside the callback. There are two kinds of constraints you can add: lazy constraints and user cuts. Lazy constraints are necessary for the structure; a solution must satisfy all lazy constraints. However, you use lazy constraints when they are too numerous to add to the model, and you only want to add those that get violated. User cuts are not necessary, but they can help remove fractional solutions and tighten the LP relaxation of a MIP. In your case, it sounds like you have lazy constraints.
You are not adding all violated lazy constraints. As stated in the documentation: "Your callback should be prepared to cut off solutions that violate any
of your lazy constraints, including those that have already been
added." You should not track whether you added a lazy constraint already; you must add it every time you see that it is violated. This is due to the parallel processing of the Gurobi solver.
I'm not sure what to search for or how to ask the question as I can't draw. Please bear with me.
If I have a rectangle with circular end caps. I want to remove some of the edges of the rectangle so there is a smooth path all round. Kinda like of you were to stretch the ends, the middle gets thinner.
I was trying to work out the chord of a larger, outer circle until I got stuck trying to work out where the circles should touch.
I can see some relationships for trigonometry, but my brain just won't go the extra mile.
Can anyone please help point me in the right direction.
Thanks.
Here is the answer:
// Small value for CSG
Delta = 0.01;
2Delta = 2 * Delta;
$fa=1; $fs=$fa;
module roudedArm(xl=50, yt=10, zh=5, in=2, bh=0.8) {
EndRadius = yt/2; // size of outer ends
EndSpacing = xl-yt; // distance between end point radii
ArmConcavity = in; // how much in does it go in on each side
ArmThickness = zh; // height in z
// Negative curve to narrow the Arm (calculated by pythagoras)
ArmCurveRadius = (pow((EndSpacing / 2), 2) - 2 * EndRadius * ArmConcavity + pow(ArmConcavity, 2)) / (2 * ArmConcavity);
// The orthogonal distance between the middle of the Arm the point it touches the round pillar sections
ArmSectionLength = (EndSpacing / 2) * ArmCurveRadius / (ArmCurveRadius + EndRadius);
// end points
lbxcylinder(r=EndRadius, h=ArmThickness);
translate([EndSpacing, 0, 0]) lbxcylinder(r=EndRadius, h=ArmThickness);
// inner curve
difference()
{
translate([EndSpacing / 2 - ArmSectionLength, -EndRadius -ArmThickness, 0])
translate([ArmSectionLength, (EndRadius + ArmThickness),0])
lbxcube([ArmSectionLength * 2, 2 * (EndRadius + ArmThickness), ArmThickness], bh=bh);
// Cut out Arm curve
translate([EndSpacing / 2, ArmCurveRadius + EndRadius - ArmConcavity, -Delta])
lbxcylinder(r = ArmCurveRadius, h = ArmThickness + 2Delta, bh=-bh);
translate([EndSpacing / 2, -(ArmCurveRadius + EndRadius - ArmConcavity), -Delta])
lbxcylinder(r = ArmCurveRadius, h = ArmThickness + 2Delta, bh=-bh);
}
}
module lbxcube(size, bh=0.8) {
// don't support bevelling in demo
translate([-size[0]/2, -size[1]/2, 0]) cube(size);
}
module lbxcylinder(r, h, bh=0.8) {
// don't support bevelling in demo
cylinder(r=r, h=h);
}
roudedArm(xl=50, yt=10, zh=5, in=2, bh=0.8);
Thanks to Rupert and his Curvy Door Handle on Thingiverse.
I have a program that compiles and flashes to the Photon without problem. It runs well until it publishes a string to PubNub. By changing the string being sent, I get different results.
The following examples are relevant:
This works:
String msg = String(tempc);
client = PubNub.publish(channel, msg);
This works:
String msg = String("24");
client = PubNub.publish(channel, msg);
This causes the photon to crash (flash red):
msg = "24.000:145:654"
client = PubNub.publish(channel, msg);
Can you advise why the introduction of delimiters (=,-,:) causes the photon to crash.
Many thanks.
I managed to solve the problem, but i'm not sure why the previous "msg" construct did not work (If anyone can shed light on this for me, I would greatly appreciate it).
Here is the msg construct that i used to solve the problem. It is now in an object form and quite easy to work with on the Javascript side.
char msgChar[150] = "";
String tempstring = "{\"tN\":\"" + oT.f2s(oT.Now()) + "\",\
\"tH\":\"" + oT.f2s(oT.Low()) + "\",\
\"tL\":\"" + oT.f2s(oT.High()) + "\",\
\"hN\":\"" + oH.f2s(oH.Now()) + "\",\
\"hH\":\"" + oH.f2s(oH.Low()) + "\",\
\"hL\":\"" + oH.f2s(oH.High()) + "\",\
\"lN\":\"" + oL.f2s(oL.Now()) + "\",\
\"lH\":\"" + oL.f2s(oL.Low()) + "\",\
\"lL\":\"" + oL.f2s(oL.High()) + "\"}";
tempstring.toCharArray (msgChar, 150);
Thank you to those of you who contributed to the solution.
I'm new to graphics and was wondering how I would go about creating an object boundary for my game.
Right now I have an object following my mouse. This works fine for my boundary when my ship has a rotation.z of 0. However, when I rotate the ship, the boundary has odd behavior.
I tried getting the world position of the ship and simply checking the x and y boundaries. However, the world position seems to give me a different x and y when I rotate. How can I
go about creating a boundary that works for all the rotations of my ship.
Here's my game(collisions turned off for purpose of help): http://www.cis.gvsu.edu/~chaua/CS371/WebGLProject/home.html
The behavior I'd like occurs when you don't rotate the ship.
Rotate the ship with left/right mouse.
Relevant code snippets(in render loop):
if(mouseLeftDown)
ship.rotation.z += leanSpeed;
if(mouseRightDown)
ship.rotation.z += -leanSpeed;
....
....
targetX = ((lastMouseX / window.innerWidth) * 2 - 1) * 90;
targetY = -((lastMouseY / window.innerHeight) * 2 - 1) * 60;
var worldPosition = (new THREE.Vector3()).getPositionFromMatrix(ship.matrixWorld);
if(worldPosition.x + targetX <= (randSpawnWidth/2)-500 && worldPosition.x + targetX >= -(randSpawnWidth/2)+500)
ship.translateX(targetX);
if(worldPosition.y + targetY <= (randSpawnHeight/2)-500 && worldPosition.y + targetY >= -(randSpawnHeight/2)+500)
ship.translateY(targetY);
I would appreciate any help. Thanks!
I am trying to implement a version of the SVG Semantic Zoom and Pan example for D3.js, found here. I am trying to do this with a Dendrogram / tree (example here), as recommended by Mike Bostock (here). The goal is like this jsFiddle that one of the other threads mentioned, except without the weird node / path unlinking behavior. My personal attempt is located here.
I was getting an error in Firebug with Mike's code, about "cannot translate(NaN,NaN)", so I changed the code in the zoom function to what is shown below. However, the behavior is weird. Now 1) my paths don't zoom / move, and 2) I can only pan the nodes from Lower Right--Upper Left (if I try panning from Lower Left--Upper Right, the nodes still move along the LR-UL direction).
var vis = d3.select("#tree").append("svg:svg")
.attr("viewBox", "0 0 600 600")
.attr("width", w + m[1] + m[3])
.attr("height", h + m[0] + m[2])
.append("svg:g")
.attr("transform", "translate(" + m[3] + "," + m[0] + ")")
.call(d3.behavior.zoom().x(x).y(y).scaleExtent([1,8]).on("zoom",zoom));
// zoom in / out
function zoom() {
var nodes = vis.selectAll("g.node");
nodes.attr("transform", transform);
}
function transform(d) {
return "translate(" + x(d.y) + "," + y(d.x) + ")";
}
I tried following the other solutions given in the Google Groups thread mentioned above and the jsFiddle, but I don't make much progress. Including the path links from the jsFiddle in my code and a translate() function lets me scale the paths--except 1) they flip vertically (somewhere x and y transposition isn't working right); 2) the paths don't zoom at the same rate as the nodes (perhaps related to #1), so they become "unlinked"; and 3) when I pan, the paths now pan in all directions, but the nodes don't move. When I click on a node to expand the tree, the paths re-adjust and fix themselves, so the update code seems to work better (but I don't know how to identify / copy the working parts of that). See my code here.
function zoom(d) {
var nodes = vis.selectAll("g.node");
nodes.attr("transform", transform);
// Update the links...
var link = vis.selectAll("path.link");
link.attr("d", translate);
}
function transform(d) {
return "translate(" + x(d.y) + "," + x(d.x) + ")";
}
function translate(d) {
var sourceX = x(d.target.parent.y);
var sourceY = y(d.target.parent.x);
var targetX = x(d.target.y);
var targetY = (sourceX + targetX)/2;
var linkTargetY = y(d.target.x0);
var result = "M"+sourceX+","+sourceY+" C"+targetX+","+sourceY+" "+targetY+","+y(d.target.x0)+" "+targetX+","+linkTargetY+"";
//console.log(result);
return result;
My questions are:
Are there any working examples of zoom / pan on a Dendrogram / tree that I can look at?
With the code I have above, can anyone identify where / how the paths are getting flipped? I have tried various permutations within the translate() function of drawing the SVG Cubic Bezier curve, but nothing seems to work right. Again, my jsFiddle is here.
Any troubleshooting tips or ideas why panning only partially works?
Thank you everyone for your help!
You had a pretty good implementation that was derailed by one major typo:
function transform(d) {
return "translate(" + x(d.y) + "," + x(d.x) + ")";
}
Should have been
function transform(d) {
return "translate(" + x(d.y) + "," + y(d.x) + ")";
}
To have your paths not flip you should have probably not reversed the y-axis:
y = d3.scale.linear().domain([0, h]).range([h, 0])
changed to
y = d3.scale.linear().domain([0, h]).range([0, h])
Fixes are here: http://jsfiddle.net/6kEpp/2/. But for future reference, you should probably have your x-axis operate on x-values, and y-axis operate on y-values, or you're just going to really confuse yourself.
Final remarks to polish your implementation:
There is a little bit of jumpiness in the bezier drawing going from the default rendering (or right after opening/closing a node) to the zoom implementation. You just need to make those the same bezier function, and it will feel a lot better when you play with it.
You need to update the zoom vector after the graph redraws itself, based on the relative movement of existing nodes. Otherwise, there will be a sudden jump when you try to zoom again after opening/closing a node.