unexpected VARSYM in zimpl - optimization

I am getting an unexpected VARSYM in my Zimpl code. Here is a portion of my code:
param T := 0.8;
var S[Sensors] binary;
minimize nb_sensors : sum < i > in Sensors : S[ i ];
subto fd:
1- prod <k,l> in Sensors*Pipe : (1-ord(Proba[k,l],1,1) * S[k]) >= T;
It seems that the error is because I have a variable (S[]) which is inside the function (prod), do you have any idea about this issue?

What is T, a variable or a constant? Have you tried to write the product in brackets:
1- (prod <k,l> in Sensors*Pipe : (1-ord(Proba[k,l],1,1) * S[k])) >= T;
or to rewrite is as:
prod <k,l> in Sensors*Pipe : (1-ord(Proba[k,l],1,1) * S[k]) + T <= 1;

Related

VHDL: Error in when conditional

This question is very basic, but I just started learning VHDL, and I can't figure out the error.
So, I'm using Quartus Prime Lite, and getting error
Error (10500): VHDL syntax error at Package_42.vhd(30) near text "when"; expecting ";"
when compiling the following piece of code.
Any ideas what could be wrong?
Thanks!
library ieee;
use ieee.std_logic_1164.all;
package Package_42 is
subtype StepType is std_logic_vector(3 downto 0);
function Problem_42(a : in std_logic;
b : in std_logic;
j : in StepType;
k : in StepType) return StepType;
end;
package body Package_42 is
function Problem_42(a : in std_logic;
b : in std_logic;
j : in StepType;
k : in StepType) return StepType is
variable Step : StepType := "----";
begin
Step := "0100" when a = '1' and b = '0' else <-- ERROR is HERE!!!
j when a = '1' else
k when b = '1' else
"----";
return Step;
end;
end package body;
First, make sure you have turned on the VHDL-2008 switch.
If that does not work, file a bug report against your tool and re-write your code using an if statement.

Tail Recursion and Iteration SML

This is my assignment.
(http://prnt.sc/aa3gwd)
I've been working on this one with a tutor and this is what we have come up with so far.
fun mult(a,b) =
let
val product = 0
in
if (a = 0) then
0
else
while a > 0 do
(
product := product + b;
if (a = 1) then
product
else
a:= a -1
);
end;
; //the function did not run at end;, so we added these two semicolons below
;
Output of this is:
stdIn:102.11-103.6 Error: syntax error: deleting SEMICOLON END SEMICOLON
I've only been introduced to SML in the last 2 weeks and I just can't get my head around it. Any help is very much appreciated.
You need two (mutable) reference variables; one for the product and one for the counter.
Something like this:
fun mult(a, b) =
let val product = ref 0
val counter = ref a
in
while !counter > 0 do (
product := !product + b;
counter := !counter - 1
);
!product
end;
(This isn't exactly a translation of the recursive code you linked to, because that code was unnecessarily complicated. You may need to adjust, depending on your professor.)
(I would write the recursive version more like this:
fun mult (0, _) = 0
| mult (_, 0) = 0
| mult (a, b) = b + mult(a - 1, b);
It's unclear why the exercise has a special case for a = 1.)

ANTLR: something wrong with list of tokens

Try (honor+=NAME|honor+=DIGIT)+ and then $honor is a list of tokens.
I took out list of $honor
for(int r = 0; r < list_honor.size(); r++)
honorstr = honorstr + list_honor.get(r).text;
input: test
output: [#752,2539:2585='test',<6>,19:11]
what is wrong?
I think the list is initialized in both alternatives:
rule
: ( honor+=NAME /* alternatvie 1 */
| honor+=DIGIT /* alternatvie 2 */
)+
;
Try something like this:
rule
: honor+=(NAME | DIGIT)+
;
or if that doesn't work, something like this:
rule
: honor+=sub_rule+
;
sub_rule
: NAME
| DIGIT
;

Currency Formatting In Sencha

I just started working on Sencha couple of hours ago. What I want is to format currency values on my app.
For example, wherever something appears like 20000 I want it to look like 20,000
I tried looking up on internet and came to know about Ext.util.Format.number
So I tried to use it like Ext.util.Format.number(total_value, “0,000.00”); wherever I was using ${total_value}. But that didn't work.
Do I have to include any external files or am I missing anything?
This is what I used in my project after realising Ext.util.Format.number() is not part of Sencha Touch, a small JS function which can be used anywhere in my app:
/**
* Given a number this will format it to have comma separated readable number(Rounded off)
* with currency symbol(Rs.) prefix
* #example
* Helper.formatCurrency(123456.78) = "Rs. 123,456"
*
* #param {Number} num
* #return {Number}
*/
formatCurrency : function(num) {
num = num.toString().replace(/\$|\,/g, '');
if (isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num * 100 + 0.50000000001);
num = Math.floor(num / 100).toString();
for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
num = num.substring(0, num.length - (4 * i + 3)) + ','
+ num.substring(num.length - (4 * i + 3));
return (((sign) ? '' : '-') + 'Rs. ' + num /*+ '.' + cents*/);
},
Feel free to copy, change and improvise
Try using Ext.util.Format.currency(“0,000.00”);
currencyConvertion : function (value){
return Number(value).toFixed(0).replace(/./g, function(c, i, a) {
return i > 0 && c !== "." && (a.length - i) % 3 === 0 ? "," + c : c;
});
}

architcture 86_64 error

Getting this error:
which seems to be connected to this, but have no idea why:
// Inline
inline float onsetsds_phase_rewrap(float phase);
inline float onsetsds_phase_rewrap(float phase){
return (phase>MINUSPI && phase<PI) ? phase : phase + TWOPI * (1.f + floorf((MINUSPI - phase) * INV_TWOPI));
}
Any ideas?