cannot write variables on the summation of cplex java - java

I have been working on a mathematical model for 3 months. I have a constraint like this:
Where x and y are decision variables, p is a parameter.
I wrote my mathematical model using Java, I tried a lot of things but all of them doesn’t work correctly or gives error.
Would you please help me?

Related

Integrality Gap in MAXIMIZATION in CPLEX+Java | Bug?

I try to solve a large MIP in which the . If it does not solve optimally, it shall return the integrality gap (that is, difference between best integer solution and best solution of the linear relaxation).
Using getMIPRelativeGap of the Java+CPLEX interface, I sometimes got values in the range of 1.0E11-1.0E13 which does not make sense, as an integrality gap should be a percentage between 0 and 1. I tracked those cases down and found out that I get those results, if the best integer solution has a value of 0 (my inner problem is a profitable tour problem, thus, if the best route is not visiting any vertice). The integrality gap should be (bestobjective-bestinteger)/bestobjective (https://www.ibm.com/support/knowledgecenter/SSSA5P_12.6.0/ilog.odms.cplex.help/refdotnetcplex/html/M_ILOG_CPLEX_Cplex_MIPInfoCallback_GetMIPRelativeGap.htm), yet, it seems to be (bestobjective-bestinteger)/bestinteger.
I also tested a couple of other values (if the integer objective is positive), and were able to confirm this in examples.
Can someone else reproduce this behavior? Does this behavior make sense to you?
Thanks :)
Indeed, the documentation for CPXgetmiprelgap in the Callable Library (C API) says the following:
For a minimization problem, this value is computed by
(bestinteger - bestobjective) / (1e-10 + |bestinteger|)
where bestinteger is the value returned by CPXXgetobjval/CPXgetobjval
and bestobjective is the value returned by
CPXXgetbestobjval/CPXgetbestobjval. For a maximization problem,
the value is computed by:
(bestobjective - bestinteger) / (1e-10 + |bestinteger|)
So, it looks like the documentation for the Java API is buggy. The Java API just calls CPXgetmiprelgap under the hood, so it should be the same. Thanks for reporting this. I'll make sure that this gets passed on to the folks who can fix it.

java.math.BigDecimal.scale() equivalent for double

I've got a matrix of values like the one below that I need to scale. I've been looking around for an inbuilt function if there is one that could do this for me. I haven't found one & so have ended up writing code to do the scaling using the below formula
scaledMatrix = (Matrix - MeanMatrix)/Standard Deviation
This code is a bit buggy & I'm working on correcting it. While I do that, I happened to bump on java.math.BigDecimal.scale() & did look up an equivalent for double as the matrix I have is double type numbers
If someone could please help me with details on
1) If there is an inbuilt function that accepts matrix of values & returns me the scaled matrix
2) `java.math.BigDecimal.scale()` equivalent for `double` type data
Any help would be much appreciated please.
The BigDecimal.scale() method does not do what you seem to think it is doing. A BigDecimal value is stored as a * 10^b (where ^ denotes exponentiation). The BigDecimal.scale() method basically returns the b part of that.
I do not know of a similar method for double values, nor do I know of a method which performs the function you need. Since you put apache-commons in the tags, I suggest you look into Apache Commons's extensive statistical library.

I need a Java library to help me solve multi-times equations

I just started using Java to simulate solar panel's performance, however the single diode model requires lots of calculations:
basically, each function is a function of the other, all of them of the variable of Rs, a.
two equations are available from f, f1.
how can i get the value of Rs, a.
I can extract Rs, a from the equations and take it to the equation of f, f1.
however, the equation will be of great difficulty to solve, as it has exp(), multi-times of the variable and ln()..
is there any library to use to calculate the value of variables by given constraint?
the equations are basically like this:
v = 3.5a
ff0= 5/v+ln(5/v+0.7)/(5/v+1)
ffs = ff0*(1-Rs*1.1)+(Rs*8)^2
....
...
..
f: 9=constant1-ffs*((exp(v-4/Rs))-1)-(15+8*Rs)*a
f1: 9=15*(ffs*.....)
thank you.
You haven't concisely characterized the kind of equations that you want to solve, but the examples look rather hairy. If they are solvable (symbolically) then a commercial package like Mathematica is probably a good bet.
But I think you'd probably be better off asking this kind of question on the
http://math.stackexchange.com/
where real mathematicians hang out. If nothing else they can characterize your equations for you and tell you if they are likely to be solvable.

Math.atan gives an error in java programming

i am using haversine formula in java programming (using eclipse).
My problem is at the end of the equation where i get an error (atan is underlined) saying that "The method atan(double) is undefined for the type Math".
i dont know what is the problem. Does anyone have an idea?
double angle = 45;
double arctan = Math.atan(angle);
Do you have any other Math class in the same package? Maybe you could try:
double angle = 45;
double arctan = java.lang.Math.atan(angle);
The only possible reason that I can think of for why this might happen is that there is a namespace conflict. That is to say that the compiler thinks the Math in your method is referencing some other Class called Math instead of java.lang.Math
In eclipse if you hover your mouse cursor over Math it will bring up a context window showing you what package it thinks Math belongs to. If it's not java.lang then that's your problem.
Are you programming mobile application and using Java ME? In that case the Math library really doesn't contains atan function. So you have to calculate atan by yourself. This topic was discussed here and also here.

Schedule notation (time ranges)

I have some code which needs to do things based on a schedule: e.g. during business hours do X, after hours do Y. The schedule will be defined by our customer's so I need a notation which can be written by people and parsed by my program. I'm thinking of something like:
12/25:0730-1730 Do Y
[Mo-Fr]:0730-1730 Do X
[Mo-Tu]:1730-0730 Do Y
Fr:1730-Mo:0730 Do Y
There will definitely be weekly variation. Yearly variation (holidays) seems likely. I would like a notation that is efficient and flexible.
I also need java code which will parse the time ranges and tell me which range a given date time is in.
I've searched the web and found nothing. Closest is CRON notation, which is not quite what I need.
Any one know of an existing notation definition and implementation?
Thanks,
For Java Joda time (Scala wrapper scala-time) is a powerful library for time calculations. You could look at the google-rfc-2445 which does something like what you are asking for (?).
If you are looking for a Java scheduler http://www.quartz-scheduler.org/ is a good option.
I don't think you will find something out of the box. In such cases it's better to do the implementation by yourself and have a full control of the code. You can use antlr to create a parser.
Add a notion of priority to your syntax. Then it will be easier to schedule someting
01.01.2011-31.01.2011 prio 1 do-idle-stuff
[Mo-Fr] prio 2 do-work
[Sa-Su] prio 2 weekend
10.02.2011-17.02.2011 prio 3 go-on-holidays

Categories

Resources