Currently running into an issue with needed to re-write the boolean expression (AB) + (~A~B) using only NAND gates. Any Ideas?
Related
I am using Gurobi through the JuMP package in Julia to solve a mixed-integer program.
I would like to obtain a graph
like this one, where also a solution based on Python is provided (which was also addressed on
Gurobi community form).
However, I have not found working solutions for Julia calling Gurobi through JuMP.
I understand that callback functions have to be used (such as this suggestion or even the main documentation here), but I do not fully understand how they work and what is essential to achieve my goal.
Any help is much appreciated, as well as a possible description of what the callback function is doing at each step.
If it helps, I am using Gurobi (v.9.0.0), JuMP (v0.20.1), MathOptInterface (v0.9.22) and Julia (v.1.3.0).
You need to use the C API. Here is a translation of Eli's answer on the Gurobi forum:
using JuMP, Gurobi
model = direct_model(Gurobi.Optimizer())
N = 30
#variable(model, x[1:N], Bin)
#constraint(model, rand(N)' * x <= 10)
#objective(model, Max, rand(N)' * x)
data = Any[]
start_time = 0.0
function my_callback_function(cb_data, cb_where::Cint)
#show cb_where
if cb_where == GRB_CB_MIP
objbst = Ref{Cdouble}()
GRBcbget(cb_data, cb_where, GRB_CB_MIP_OBJBST, objbst)
objbnd = Ref{Cdouble}()
GRBcbget(cb_data, cb_where, GRB_CB_MIP_OBJBND, objbnd)
push!(data, (time() - start_time, objbst[], objbnd[]))
end
return
end
MOI.set(model, Gurobi.CallbackFunction(), my_callback_function)
start_time = time()
optimize!(model)
open("data.csv", "w") do io
for x in data
println(io, join(x, ", "))
end
end
p.s. please update to Julia 1.6 and JuMP 0.22. I have not tested whether this works on the older version.
In Powershell, I have a list of different subroutes and I need to define all possible start/end points from the route. Let me clearify by showing an example.
This is the list of subroutes. These are all objects with a property that defines whether it is a possible starting point or not. In this example, only $A is a starting point.
$subroutes = #(
#($A, $B),
#($A, $C),
#($B, $D),
#($B, $E),
#($D, $F),
#($C, $E)
)
For example: you can go from A to B and then from B to 3 other destinations. The final result would be:
- A ==> F (A to B to D to F)
- A ==> E (A to B to E) OR (A to C to E)
I am quite new to Powershell and have learned a lot already, but I cannot seem to find a decent piece of code to manage this. What is the best combination of cmdlets to traverse all possible subroutes and make sure I can find all possible routes?
I want to run around 100 simulations with my model changing two parameters f and TLoadand track the changes on the phase currents currentSensor.i[1] etc.
Now I'm stuck with the documentation on the Wolfram website because there is no definite explanation on how to use scripting with the SystemModeler. I found for example this link on the Wolfram site with some code but no explanation in which commandline I should use it.
I downloaded the WolframScript program and tried to open my model with wolframscript -file SMPM_VoltageSource_Inverter.mo but it says ToExpression::sntx: Invalid syntax in or before ... eventhouh my model simulates totally fine and without any errors in the SimulationCenter.
Can someone explain to me:
Is it possible to write scripts ?
If Yes:
How can I simulate my model?
How can I do a parameter sweep of f and TLoad? Is it as described in the link?
Is it possible to export data of currentSensor.i[1] as a csv-file? And how to?
Thank you for any help!
I don't know about wolfram sorry, but for OpenModelica the following works:
// to load Model from file use
// loadFile("fileName.mo");
loadString("
model M
parameter Real a = 1;
Real x;
equation
x = a * sin(time);
end M;
"); getErrorString();
buildModel(M); getErrorString();
for a in {1,2,3,4} loop
str_a := String(a); getErrorString();
system("./M -override a=" + str_a); getErrorString();
// for windows use
//system("M.exe -override a=" + str_a); getErrorString();
system("mv M_res.mat " + "M_" + str_a + ".mat");
end for;
Put this in a file named for example model.mos and call it from terminal or command line, depending on your os, with omc model.mos if you have OpenModelica installed. this should generate a csv.
EDIT: I realized the original just saves the last value of x, you might want the full output. Therefore i changed the .mos-file. Each different result will be saved in a different file, if you want to change it to csv you just have to change the generated xml.
The expression is : AD' + A'B + C'D + B'C. Any hint or something would be more than awesome.
Thank you.
Hint, Law of distribution: http://www.wolframalpha.com/input/?i=%28a+AND+b%29+OR+%28c+AND+d%29
What you want is the CNF (Conjunctive Normal Form) instead of DNF.
Can anyone help me to simplify this boolean function into two logic gates?
C(out) = AC(in) + BC(in) + AB
This expression represents what is commonly known as a three input majority gate - the output is TRUE only when the majority of inputs are true (2 or 3 inputs must be true for the 3 input case). In general it takes 4 basic logic gates to implement this (5 if you you are restricted to 2-input gates).
If you Google for "majority gate" you will find a variety of implementations, e.g. on this page I found the following, which I think matches your criteria (other than the unfeasible requirement of doing it with only 2 gates):
About majority function with n boolean variables.
for n variables, f(x1,x2,...xn) there will be total nC[n/2] terms for OR operation. Each term contains [n/2] variables for AND operation.
ex: f(00111)= OR{ and(0,0,1) and(0,0,1) and(0,0,1) and(0,1,1) and(,0,1,1) and(0,1,1,) and(0,1,1) and (0,1,1,) and(0,1,1,) and(1,1,1 )
=0 OR 0 OR 0 OR...... OR 1=1=majority of ones is true.