BINARY VARIABLE SHOWING ONY VALE ZEROS

89 views
Skip to first unread message

khan

unread,
Jan 3, 2018, 6:11:45 AM1/3/18
to AMPL Modeling Language
Hi All,

I have a little program defined as below. I want to define a Binary variable Xku such that its 1 if SUBCAR is assigned to some USERS. I have defined Xku as below. But when I display Xku its all Zero column. Anybody knows what wrong I am doing?

AMPL .MOD
===========================================
set SUBCAR:=1..nsb by 1;
set USERS:=1..nu by 1;

set BAMP within {SUBCAR,USERS};
param amp{BAMP} >=0;

#binary variable
var Xku{BAMP} binary;

==========================================

AMPL .DAT
==========================================
param: BAMP: amp :=
1 1 .3
2 1 .4
3 1 .9
4 1 1
5 1 .32
6 2 .8
7 2 .6
8 2 .54
9 2 .31
10  2 .21;
=========================================

DISPLAY:
Xku :=
1  1   0
2  1   0
3  1   0
4  1   0
5  1   0
6  2   0
7  2   0
8  2   0
9  2   0
10 2   0

=================================================
DESIRED OUTPUT:
Xku :=
SUBCAR USERS Xku USERS Xku
1  1   1  2  0
2  1   1  2  0
3  1   1  2  0
4  1   1  2  0
5  1   1  2  0
6  1   0  2  1
7  1   0  2  1
8  1   0  2  1
9  1   0  2  1
10 1   0 2  1

ptiwari

unread,
Jan 3, 2018, 3:59:15 PM1/3/18
to AMPL Modeling Language
 You could specify lower or upper bounds for variables and use it in the objectives and constraints to get the value of variables, but you are trying to fix the value of variables. Instead of using variables for fixed values, you should use param to specify your data. You could declare a param and assign the values to param like the way you did for amp.

Thanks,
Paras

khan

unread,
Jan 4, 2018, 10:05:43 AM1/4/18
to AMPL Modeling Language
Thank you for the response.

You mean that for the Binary variable I also have to give the values to it using param? This is what i understood.

What I was assuming is that when I declare some variable as binary I have to express it in such a way that it understand what value is 0 and 1 corresponding to the existing definition of the data.

So it means that binary variable in AMPL is not going to take the vaules itslef but i have to express it using param in my .dat file? Is it like this, no?
Can you give me any example for this?

Thanking you in anticipation.

ptiwari

unread,
Jan 4, 2018, 1:16:01 PM1/4/18
to AMPL Modeling Language
You can find one example in https://ampl.com/BOOK/CHAPTERS/23-integer.pdf (page number 442). You don't need to give value to binary variable, solver will calculate the optimal value of variable based on your constraints and objectives. You were trying to set the values of variable and I was suggesting to you that you need to use param data structure to set the value. 

Thanks,
Paras

Muhammad umar

unread,
Jan 11, 2018, 5:51:54 AM1/11/18
to am...@googlegroups.com
Thank you for your feedback. It was useful to the point reading. I have advanced by your suggested reading. And I understood that I dont need to give values to a bianry variable. But still I am having a problem with the decision variable. When I use the binary variable in to my Objective function the values are different and display shows that my binary variable Xku is all zero.

Pleas have a look. I will wait for your response.

---------------------------------My model file------------------------
set eNB;
set SUBCAR;

param Pmax{eNB} >= 0;
param Preq{SUBCAR} >= 0;

#check: sum{i in eNB} Pmax[i]=sum{j in SUBCAR} Preq[j];

param intf{eNB,SUBCAR} >=0;
var Pall{eNB,SUBCAR} >=0;
var Xku{eNB,SUBCAR} binary;

#Objective isto Minimiza interference
minimize Total_Interference:
    sum{i in eNB, j in SUBCAR} intf[i,j] * Pall[i,j]*Xku[i,j];

#Maximum Power
subject to PMAX{i in eNB}: sum{j in SUBCAR} Pall[i,j]  =  Pmax[i];

#Power of UEs
subject to PREQ{j in SUBCAR}: sum {i in eNB} Pall[i,j] =  Preq[j];

subject to total: sum{i in eNB} Pmax[i]<=sum{j in SUBCAR} Preq[j];

---------------------------------My data file----------------------------------

param: eNB: Pmax:=
       eNB1 200
       eNB2 170;

param: SUBCAR: Preq:=
        1     90
        2     10
        3     60
        4     40
        5     170;

param intf: 1 2 3 4 5:=
eNB1 3  1   11   1  16
eNB2 27  9    12   9   26;


-- 
Best Regards 
M. Umar Khan

--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/Tg9iryPDuN8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+unsubscribe@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.

ptiwari

unread,
Jan 11, 2018, 2:32:44 PM1/11/18
to AMPL Modeling Language
You are minimizing the objective function and multiplying the objective term by Xku. There is no constraint on Xku and Xku is a binary variable. The solver sets Xku to zero because setting zero to Xku minimizes the objective function. So it seems that you are missing some constraints in your formulation. The term Xku should appear in some constraints in your formulation.

Thanks,
Paras
To unsubscribe from this group and all its topics, send an email to ampl+uns...@googlegroups.com.

Muhammad umar

unread,
Jan 12, 2018, 5:20:13 AM1/12/18
to am...@googlegroups.com
Thank you so much for the correction. I did introduce the Xku in the constraints. Also did some more changes. now it becomes a non linear objective.
Please have a look and see how can I linearise this?

------MY model file-------------------

set eNB;
set SUBCAR;

param Pmax{eNB} >= 0;
param Ppwr{SUBCAR} >= 0;


#check: sum{i in eNB} Pmax[i]=sum{j in SUBCAR} Preq[j];

param intf{eNB,SUBCAR} >=0;
var Pall{eNB,SUBCAR} >=0;
var Xku{eNB,SUBCAR} binary;

#Objective isto Minimiza interference
minimize Total_Interference:
    sum{i in eNB, j in SUBCAR} (intf[i,j])^2 * (Pall[i,j])^2 *Xku[i,j];

#Maximum Power
subject to PMAX{i in eNB}: sum{j in SUBCAR} (Pall[i,j])^2 *Xku[i,j] <=  Pmax[i];

#Peak Power of UEs
subject to PPWR{j in SUBCAR}: sum {i in eNB} (Pall[i,j])^2 *Xku[i,j] <=  Ppwr[j];

subject to total: sum{i in eNB} Pmax[i]<=sum{j in SUBCAR} Ppwr[j];

--------------My data file----------------------

param: eNB: Pmax:=

eNB1 165

eNB2 205;


param: SUBCAR: Ppwr:=

1 100

2 10

3 50

4 40

5 170;


param intf: 1 2 3 4 5:=

eNB1 3 11 11 1 16

eNB2 27 9 12 9 26;



-- 
Best Regards 
M. Umar Khan

To unsubscribe from this group and all its topics, send an email to ampl+unsubscribe@googlegroups.com.

ptiwari

unread,
Jan 12, 2018, 2:12:09 PM1/12/18
to AMPL Modeling Language
Does your formulation require squaring pall variable? If you could reformulate your model and have the quadratic term only then your could follow the https://orinanobworld.blogspot.mx/2010/10/binary-variables-and-quadratic-terms.html article to linearize your formulation.

Thanks,
Paras

On Wednesday, January 3, 2018 at 3:11:45 AM UTC-8, khan wrote:

Muhammad umar

unread,
Jan 15, 2018, 5:30:12 AM1/15/18
to am...@googlegroups.com
Lets remove squaring for a while. I am running this with 'cplex'. And got all zeros in Pall. And two 1 in Xku. When I run with solver 'loqo' it gives me even decimal values in Binary variable Xku.

I have a doubt on the binary constraint: subject to BVARXku{i in eNB}: sum{j in SUBCAR} Xku[i,j]=1;

Do you think its okay?

--------------Model file----------------

set eNB;
set SUBCAR;

param Pmax{eNB} >= 0;
param Ppwr{SUBCAR} >= 0;

#check: sum{i in eNB} Pmax[i]=sum{j in SUBCAR} Preq[j];

param intf{eNB,SUBCAR} >=0;
var Pall{eNB,SUBCAR} >=0;
var Xku{eNB,SUBCAR} binary;

#Objective isto Minimize interference
minimize Total_Interference:
    sum{i in eNB, j in SUBCAR} intf[i,j] * Pall[i,j] * Xku[i,j] ;


#Maximum Power
subject to PMAX{i in eNB}: sum{j in SUBCAR} Pall[i,j]  <=  Pmax[i];

#Peak Power of UEs
subject to PPWR{j in SUBCAR}: sum {i in eNB} Pall[i,j]  <=  Ppwr[j];

#Binary Variable
subject to BVARXku{i in eNB}: sum{j in SUBCAR} Xku[i,j]=1;

subject to total: sum{i in eNB} Pmax[i]<=sum{j in SUBCAR} Ppwr[j];

-------------DATA FILE---------------

param: eNB: Pmax:=
       eNB1 200
       eNB2 170;

param: SUBCAR: Ppwr:=

        1     90
        2     10
        3     60
        4     40
        5     170;

param intf: 1 2 3 4 5:=
eNB1 3  1   11   1  16
eNB2 27  9    12   9   26;


-- 
Best Regards 
M. Umar Khan

--

Muhammad umar

unread,
Jan 15, 2018, 5:35:50 AM1/15/18
to am...@googlegroups.com
CPLEX OUTPUT IS THIS:

CPLEX 12.8.0.0: optimal integer solution; objective 0
0 MIP simplex iterations
0 branch-and-bound nodes
No basis.

-- 
Best Regards 
M. Umar Khan

ptiwari

unread,
Jan 15, 2018, 2:36:08 PM1/15/18
to AMPL Modeling Language
You have declared the variable as a binary and you don't need any extra constraint to make it binary. You are getting decimal value in loqo because loqo doesn't handle the binary variables. You need to use the solver that handles binary variable and cplex is one that solver.

Thanks
Paras
To unsubscribe from this group and all its topics, send an email to ampl+uns...@googlegroups.com.

Muhammad umar

unread,
Jan 16, 2018, 3:03:05 AM1/16/18
to am...@googlegroups.com
So you mean that I dont need this: subject to BVARXku{i in eNB}: sum{j in SUBCAR} Xku[i,j]=1;  ?



-- 
Best Regards 
M. Umar Khan

To unsubscribe from this group and all its topics, send an email to ampl+unsubscribe@googlegroups.com.

Muhammad umar

unread,
Jan 16, 2018, 5:07:45 AM1/16/18
to am...@googlegroups.com
A new thing I have observed that when I minimize it, it gives me Objective: 0
When I maximize it it give me some value. Whats wrong with this model?


set eNB;
set SUBCAR;

param Pmax{eNB} >= 0;
param Ppwr{SUBCAR} >= 0;

#check: sum{i in eNB} Pmax[i]=sum{j in SUBCAR} Preq[j];

param intf{eNB,SUBCAR}>=0;
var Pall{eNB,SUBCAR}>=0;
var Xku{eNB,SUBCAR} binary;

#Objective isto Minimize interference
minimize Total_Interference:
    sum{i in eNB, j in SUBCAR} intf[i,j] * Pall[i,j] * Xku[i,j] ;

#Maximum Power
subject to PMAX{i in eNB}: sum{j in SUBCAR} Pall[i,j]  <=  Pmax[i];

#Peak Power of UEs
subject to PPWR{j in SUBCAR}: sum{i in eNB} Pall[i,j]  <=  Ppwr[j];

#subject to total: sum{i in eNB} Pmax[i]<=sum{j in SUBCAR} Ppwr[j];

-- 
Best Regards 
M. Umar Khan

ptiwari

unread,
Jan 16, 2018, 2:22:46 PM1/16/18
to AMPL Modeling Language
Your binary variable Xku doesn't appear in the constraint. What is the minimum value of any non-negative expression? It's zero, right? Therefore, solver sets zero to Xku and return zero to objective. The maximum is different. What is the maximum value of non-negative expression? It's infinity. The optimal value is determined by the constraints.

Thanks,
Paras

Muhammad umar

unread,
Jan 17, 2018, 3:35:10 AM1/17/18
to am...@googlegroups.com
But I dont want 0 value. How should I do then? What should I do to get some value but not zero for this non-negative expression? Please suggest. I would be grateful.

When i write Xku in my constraints as(I still get zero value):

-----------------------------------------------------------------------------------------------------
subject to PMAX{i in eNB}:  sum{j in SUBCAR} Pall[i,j] * Xku[i,j] <=  Pmax[i];

subject to PPWR{j in SUBCAR}:  sum{i in eNB} Pall[i,j]  * Xku[i,j] <=  Ppwr[j];
-----------------------------------------------------------------------------------------------------

CPLEX OUTPUT
----------------------------------------------------------------------------------------------------
CPLEX 12.8.0.0: QP Hessian is not positive semi-definite.

0 MIP simplex iterations
0 branch-and-bound nodes
No basis.
Objective is: 0.000000
---------------------------------------------------------------------------------------------------

-- 
Best Regards 
M. Umar Khan

To unsubscribe from this group and all its topics, send an email to ampl+unsubscribe@googlegroups.com.

Muhammad umar

unread,
Jan 17, 2018, 4:49:50 AM1/17/18
to am...@googlegroups.com
Dear Paras,

I have applied Paul's method of linearisation in my model but so far no success. please have a look here. I will be grateful!

------------------Model File-----------------

set eNB;
set SUBCAR;

param Pmax{eNB} >= 0;
param Ppwr{SUBCAR} >= 0;

param intf{eNB,SUBCAR}>=1;
var Pall{i in eNB,j in SUBCAR} >=1, <= Pmax[i];
var Xku{eNB,SUBCAR} binary;
var z;

#Objective isto Minimize
minimize Total_Inter:

     sum{i in eNB, j in SUBCAR} intf[i,j] * Pall[i,j] * Xku[i,j] ;


subject to PMAX{i in eNB}:  sum{j in SUBCAR} Pall[i,j] * Xku[i,j] <=  Pmax[i];

#Z Constraints
subject to z0{i in eNB, j in SUBCAR}: z <= Pmax[i]*Xku[i,j];
subject to z1{i in eNB, j in SUBCAR}: z >= 1*Xku[i,j];
subject to z2{i in eNB, j in SUBCAR}: z <= Pall[i,j] - 1*(1-Xku[i,j]);
subject to z3{i in eNB, j in SUBCAR}: z >= Pall[i,j] - Pmax[i]*(1-Xku[i,j]);



subject to PPWR{j in SUBCAR}:  sum{i in eNB} Pall[i,j]  * Xku[i,j] <=  Ppwr[j];

---------------------Data File---------------------------------

param: eNB: Pmax:=
       eNB1 200
       eNB2 170;

param: SUBCAR: Ppwr:=
        1     90
        2     10
        3     60
        4     40
        5     170;

param intf: 1 2 3 4 5:=
eNB1 3  1   11   1  16
eNB2 27  9    12   9   26;

----------------------------------------------------------------------

-- 
Best Regards 
M. Umar Khan

ptiwari

unread,
Jan 17, 2018, 3:49:03 PM1/17/18
to AMPL Modeling Language
The dimension of z should be same as the dimension of other variables. So, your declaration of z should be:

var z{eNB,SUBCAR};

Now, you need to replace the product of Pall[i,j] * Xku[i,j] by z. So, your objective function will be

minimize  Total_Inter:

sum{i in eNB, j in SUBCAR} intf[i,j] * z[i,j]  ;


Similarly, you have the product of two variables in constraints and replace those by 'z'. Moreover, you need to properly index 'z' in the constraint.

Muhammad umar

unread,
Jan 19, 2018, 1:58:19 PM1/19/18
to am...@googlegroups.com
I did like this:

----------------------------------------------------------------
#Z-Constraints
subject to z0{i in eNB, j in SUBCAR}: z[i,j] <= Pmax[i]*Xku[i,j];
subject to z1{i in eNB, j in SUBCAR}: z[i,j] >= 1*Xku[i,j];
subject to z2{i in eNB, j in SUBCAR}: z[i,j] <= Pall[i,j] - 1*(1-Xku[i,j]);
subject to z3{i in eNB, j in SUBCAR}: z[i,j] >= Pall[i,j] - Pmax[i]*(1-Xku[i,j]);

It is giving me the same constant value. Even with other normal constraints or without them. other two normal constraints are:
subject to PMAX{i in eNB}:  sum{j in SUBCAR} z[i,j] <=  Pmax[i];
subject to PPWR{j in SUBCAR}:  sum{i in eNB} z[i,j] <=  Ppwr[j];

Does it make any sense?


-- 
Best Regards 
M. Umar Khan

To unsubscribe from this group and all its topics, send an email to ampl+unsubscribe@googlegroups.com.

ptiwari

unread,
Jan 19, 2018, 3:18:12 PM1/19/18
to AMPL Modeling Language
Your constraint looks correct.

Muhammad umar

unread,
Jan 22, 2018, 4:03:10 AM1/22/18
to am...@googlegroups.com
Hi

What do you suggest about working with the mormal constraints as well? or without them? Because I am getting the same results.

-- 
Best Regards 
M. Umar Khan

To unsubscribe from this group and all its topics, send an email to ampl+unsubscribe@googlegroups.com.

ptiwari

unread,
Jan 22, 2018, 5:03:21 PM1/22/18
to AMPL Modeling Language
It's possible to get the same optimal value even if adding new constraint. The new constraint might not change your feasible space. You need to check if the optimal value makes sense to your problem.

Thanks,
Paras

Muhammad umar

unread,
Jan 22, 2018, 5:08:57 PM1/22/18
to am...@googlegroups.com
No it does not making any sense sine my binary variable having all 1s. How this is possible. I am stuck!!

-- 
Best Regards 
M. Umar Khan

To unsubscribe from this group and all its topics, send an email to ampl+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages