Is it possible to not use cardinality constraint to generate solution candidates in clingo? - answer-set-programming

I'm learning Answer Set Programming by solving the zebra puzzle.
I found some solution examples online.
But someone told me that I can solve the puzzle without using cardinality constraint macro to generate solution Candidates.
Like without using this
{ color(House, Color) : colors(Color) }= 1 :- houses(House).
{ color(House, Color) : houses(House) }= 1 :- colors(Color).
the goal is to generate different models with a unique combination of color(House, Color).
Is this possible without {atom: atom}=1:-atoms.?

You can do this with inequality constraints, and a weak constraint to generate the maximal number of combinations.
% Generate assignments of colors to houses.
{ color(House, Color) } :- houses(House), colors(Color).
% A house can only have one color.
:- color(House, Color_1), color(House, Color_2), houses(House),
colors(Color_1), colors(Color_2), Color_1 != Color_2.
% Each color can only be assigned to one house.
:- color(House_1, Color), color(House_2, Color), colors(Color),
houses(House_1), houses(House_2), House_1 != House_2.
% Generate a maximal number of combinations (i.e. all of them).
:~ color(House, Color), houses(House), colors(Color). [-1#0, House, Color]
Although, this needlessly more verbose than your current encoding.

Related

SSRS: Custom colors for the Category axis of a stacked bar chart

I have a stacked bar chart that only ever has 5 categories(but the value of the categories change from year to year, it is a sliding 5 year window).
I have successful customised the bars to the colors I want.
But now I wish to make the label of each Category the same color as the customised bar color.
Is there a way to do this?
You can use custom code for this.
In Report Properties | Code, you can paste in the following code:
Private colourPalette As String() = {"#418CF0", "#FCB441", "#DF3A02", "#056492", "#BFBFBF", "#1A3B69", "#FFE382", "#129CDD", "#CA6B4B", "#005CDB", "#F3D288", "#506381", "#F1B9A8", "#E0830A", "#7893BE"}
Private count As Integer = 0
Private mapping As New System.Collections.Hashtable()
Public Function GetColour(ByVal groupingValue As String) As String
If mapping.ContainsKey(groupingValue) Then
Return mapping(groupingValue)
End If
Dim c As String = colourPalette(count Mod colourPalette.Length)
count = count + 1
mapping.Add(groupingValue, c)
Return c
End Function
This will give you the option of the pastel colour palette. If you want other colours, simply replace the hex colour codes with values of your choice.
To use this, simply use the following expression:
=Code.GetColour(Fields!Thingy.Value)
Use this on your series and your label fill expressions. This will ensure that the same colour appears for both. If you have multiple graphs with the same values in, this will also ensure that the same data series across multiple graphs always have the same colour.

Clingo: Compare String Literals by Order (Index)?

I have defined a color palette called tableau10 in Clingo:
tableau10(blue;orange;red;teal;green;yellow;purple;pink;brown;gray).
Is there a way to compare the colors by the order they appear in my color definition? (e.g., blue = 0, orange = 1, red = 2, ...)
My goal is to be able to claim things like blue < orange, blue < gray...
The predicate tableau10 is unordered. To do such comparisons you'd have to encode order in one way or another. You could for example assign numbers to the colors value(blue, 1). value(orange, 2). ... and compare the associated numbers when necessary, or you could write lessthan(blue, orange). lessthan(orange, red). ... lessthan(brown,gray). and also add the transitivity rule lessthan(A, C) :- lessthan(A, B), lessthan(B, C).

Unity is returning material color slightly wrong

I have this mini task in my game where you need to click trophies to change color of the wood on them. I have two arrays of colors, one is an array containing all possible colors and the other one contains four colors (the answer) as follows:
I've double checked that the colors are equal between the two arrays. For example the purple in Colors-array has exactly the same r, g, b & a values as the purple in the Right Order-array.
To check whether the trophies has correct color I just loop through them and grab their material color. Then I check that color against the Right Order-array but it's not quite working. For example when my first trophy is purple it should be correct, but it's not because for some reason Unity is returning slightly different material color than excepted:
Hope somebody knows why this is happening.
When you say, they are exactly same color, I assume you are referring rgb values from Color Inspector, which are not precise values.
Now I dont know what could be causing in different values of colors but
You can write an extension method to compare the values after rounding them to closest integer.
public static class Extensions
{
public static bool CompareRGB(this Color thisColor, Color otherColor)
{
return
Mathf.RoundToInt(thisColor.r * 255) == Mathf.RoundToInt(otherColor.r * 255) &&
Mathf.RoundToInt(thisColor.b * 255) == Mathf.RoundToInt(otherColor.b * 255) &&
Mathf.RoundToInt(thisColor.g * 255) == Mathf.RoundToInt(otherColor.g * 255);
}
}
usage:
Color red = Color.Red;
red.CompareRGB(Color.Red); // true;
red.CompareRGB(Color.Green); // false;
Hope this helps.
I would use a palette. This is simply an array of all the possible colors you use (sounds like you have this). Record, for each "trophy", the INDEX into this array, at the same time you assign the color to the renderer. Also, record the index for each "button", at the same time you assign the color to the renderer.
Then you can simply compare the palette index values (simple integers) to see if the color matches.

Colored graph isomorphism?

I have two colored graphs. I want to determine if they are isomorphic, with the condition that the isomorphism must preserve vertex color. Is there an algorithm in networkx to do this?
The graphs are undirected and simple.
Check the documentation for is_isomorphic. It takes an optional argument nodes_match which is a function that tests some condition on the two nodes. It is called by node_match(G1.node[n1], G2.node[n2]). So in this case, you want a function that tests whether the colors are matching.
import networkx as nx
def colors_match(n1_attrib,n2_attrib):
'''returns False if either does not have a color or if the colors do not match'''
try:
return n1_attrib['color']==n2_attrib['color']
except KeyError:
return False
G=nx.Graph()
G.add_node(1, color='y')
G.add_node(2, color='b')
H=nx.Graph()
H.add_node('a', color='y')
H.add_node('b', color = 'b')
nx.is_isomorphic(G,H,node_match=colors_match)
>True
H.add_node('c', color='r')
nx.is_isomorphic(G,H,node_match=colors_match)
>False

How to determine whether colour is within a range of shades

I am not sure if this is possible as I have been looking for a few hours and cant find what I am looking for.
What i am doing is taking a color from a game panel which is semi translucent so the color which I am taking is always subtly changing. What is need is a way to check if it is +/- 10 or so shades of my desired color.
Something like
If color1 is +/-10 of 0x?
I have tried using the image search to do similar but that didn't work.
Any help would be greatly appreciated
In addition to Robert's answer, you can compare the colors mathematically.
First start by separating the Red, Green, and Blue values.
ToRGB(color) {
return { "r": (color >> 16) & 0xFF, "g": (color >> 8) & 0xFF, "b": color & 0xFF }
}
Then we need a function that compares the colors. Each of thee variables holds a number representing the difference in the two color values. For example if red is 255 in c1, and 200 in c2, rdiff will be 55. We use Abs so that we don't end up with -55 when c2 has a higher value. Then we make sure the difference for each of these is less than our vary.
Compare(c1, c2, vary=20) {
rdiff := Abs( c1.r - c2.r )
gdiff := Abs( c1.g - c2.g )
bdiff := Abs( c1.b - c2.b )
return rdiff <= vary && gdiff <= vary && bdiff <= vary
}
Here's how it can be used. We take some numbers, and then compare them to each other with the default vary of 20.
light_pink := ToRGB(0xFFAAFF)
darker_pink := ToRGB(0xFAACEF)
purple := ToRGB(0xAA00FF)
MsgBox % Compare(light_pink, dark_pink) ; True
MsgBox % Compare(light_pink, purple) ; False
I assume that your read about the limitations of PixelGetColor: Known limitations:
"A window that is partially transparent or that has one of its colors marked invisible (TransColor) typically yields colors for the window behind itself rather than its own.
PixelGetColor might not produce accurate results for certain applications. If this occurs, try specifying the word Alt or Slow in the last parameter."
When using ImageSearch, you can specify the Delta of the colours. Example:
ImageSearch, FoundX, FoundY, %SearchRangeLeft%, %SearchRangeTop%, %SearchRangeRight%, %SearchRangeBottom%, *20 %ImageFile%
Here the *20 indicates the variation in the range from 0 to 255 of my search colour. When searching for a pixel inside the image of 100,100,100 (RGB), it will match anything between 80,80,80 and 120,120,120. Hope this helps, but matching transparent colours is difficult and prone to errors. The smaller the image and search range the better (and faster)