is there a function for count in MATHPROG?

View: New views
2 Messages — Rating Filter:   Alert me  

is there a function for count in MATHPROG?

by Rafael Torres-3 :: Rate this Message:

| View Threaded | Show Only this Message

I'm looking for a function that count number of objects that belong to a
specific cluster but I dont know if such function exists.

For example I'm trying to count number of objects in variable Z[i] but
with Cardinal function I get an error tha says "invalid preceding
operator == "  what does it mean?

Thanks in advance.


This is my code:

# PARAMETROS
param noitems          ; # numero de items
param nometodos        ; # numero de metodos
#param nocategorias    ; # numero de categorias

# CONJUNTOS
set ITEMS            := 1..noitems            ; # Items
set METODOS            :=    1..nometodos        ; # Metodos
set CATEGORIAS        ; # Categorias


# DATOS
param clasini{i in ITEMS , j in METODOS} , integer    ;
param nocategorias := card(CATEGORIAS);
param Porcentaje{k in 1.. nocategorias} ;

# VARIABLES DE DECISION
#var Z{ITEMS} in CATEGORIAS , integer     ;
var Z{i in ITEMS}  ;

# VARIABLES AUXILIARES PARA LINEALIZAR
var T{i in ITEMS, j in METODOS}  ;


# MODELO MATEMATICO
     # Funcion objetivo
     minimize distance: sum{i in ITEMS , j in METODOS} T[i,j]    ;

     # Restricciones
     s.t. Positivo{i in ITEMS , j in METODOS }:  Z[i] - clasini[i,j] <=
T[i,j]    ;
     s.t. Negativo{i in ITEMS , j in METODOS }: -Z[i] + clasini[i,j] <=
T[i,j]    ;
     s.t. Proporcion{k in 1..card(CATEGORIAS)}: card({i in ITEMS: k in
Z[i]}) <= noitems*Porcentaje[k];
solve;

--
Rafael Torres





"La luna se puede tomar a cucharadas o como una cápsula cada dos horas..."
- Jaime Sabines -


_______________________________________________
Help-glpk mailing list
Help-glpk@...
https://lists.gnu.org/mailman/listinfo/help-glpk

Re: is there a function for count in MATHPROG?

by Andrew Makhorin :: Rate this Message:

| View Threaded | Show Only this Message

> I'm looking for a function that count number of objects that belong to a
> specific cluster but I dont know if such function exists.
>
> For example I'm trying to count number of objects in variable Z[i] but
> with Cardinal function I get an error tha says "invalid preceding
> operator == "  what does it mean?

>      s.t. Proporcion{k in 1..card(CATEGORIAS)}: card({i in ITEMS: k in
> Z[i]}) <= noitems*Porcentaje[k];

You cannot write 'k in Z[i]', because Z[i] is not a set.

Assuming that Z models an indicator function (does it?) of a subset of
some predefined set, which (subset) needs to be found, and Z[i] is a
binary variable, the cardinality of that subset can be expressed as
'sum{i in ...} Z[i]', so you could write your constraint as follows:

s.t. Proporcion{k in 1..card(CATEGORIAS)}:
       sum{i in ITEMS: k in ...} noitems * Porcentaje[k] * Z[i];




_______________________________________________
Help-glpk mailing list
Help-glpk@...
https://lists.gnu.org/mailman/listinfo/help-glpk